这只是从价格范围搜索 POST 控制器到添加到购物车 GET 控制器
并且添加到购物车的 GET 控制器方法只是将 back() 返回到来自请求的页面。在这种情况下,问题就出现了。它无法将 back() 返回到后控制器。那么可能的解决方案是什么!
价格范围搜索路线:-
Route::post('/price-range-search', 'WelcomeController@price_range_search');
加入购物车路线:-
Route::match(['get', 'post'], '/add-to-cart/{id}', 'CartController@add_to_cart');
checkRoutesimageshere:
price_range_search 控制器功能:-
`
public function price_range_search(Request $request)
{
$data = array();
$data['price_range'] = $request->input('price_range');
// echo $data['price_range'];
$min_max = explode(',', $data['price_range']);
$min = $min_max[0];
$max = $min_max[1];
$search_result = DB::table('tbl_product')
->whereBetween('product_price', array($min, $max))
->orderBy('product_id', 'desc')
->get();
// echo "<pre>";
// print_r($search_result);
// exit();
$search_content = view('pages.search')
->with('min', $min)
->with('max', $max)
->with('search_result', $search_result);
return view('index')
->with('content', $search_content);
}
img of price_range_search Controller Function
添加到购物车路由控制器功能:-
公共函数 add_to_cart($id, Request $request) {
$product_info = DB::table('tbl_product')
->where('product_id', $id)
->first();
$data['id'] = $product_info->product_id;
$data['name'] = $product_info->product_name;
$data['price'] = $product_info->product_price;
$qty = $request->product_quantity;
if ($qty > 1) {
$data['qty'] = $qty;
} else {
$data['qty'] = 1;
}
$data['options'] = array('image' => $product_info->product_image);
Cart::add($data);
Session::put('message', ' Your Cart Item(s) are Updated! ');
// return back()->send();
return redirect()->back()->withInput(Input::all());
// return Redirect::to('/show-cart');
}
`
img of add-to-cart Controller Function:-
注意:这只是从 price-range-search POST Controller 到 add-to-cart GET Controller 和 add-to-cart GET Controller 方法只返回 back() 到请求来自的页面。在这种情况下,问题就出现了。它无法将 back() 返回到后控制器。那么可能的解决方案是什么!
这实际上不是答案。但是@rits 和@Mohamed Ahmed 都希望看到这两个路由和控制器方法的代码。但是在评论中无法提供信息,这就是为什么发布作为答案。很抱歉。