我有這一切,但似乎沒有發生在選擇和切換?這裏是所有的代碼,我...
<select class="form-control" name="SortbyList" >
<option value="1">Highest Avg</option>
<option value="2">Lowest Avg</option>
<option value="3">Another Sort option</option>
<option value="2">another sort option</option>
</select>
和控制器:
$productsQuery = Product::where('approved', '=', 1)->leftJoin('reviews', 'reviews.products_id', '=', 'products.id')->select('products.*', DB::raw('AVG(ratings) as ratings_average'))->groupBy('products.id');
switch ($request->SortbyList) {
case 1:
$productsQuery = $productsQuery->orderBy('ratings_average', 'DESC');
break;
case 2:
$productsQuery = $productsQuery->orderBy('ratings_average', 'ASC');
break;
case 3:
$productsQuery = $productsQuery->orderBy('ratings_average', 'ASC');
break;
case 4:
$productsQuery = $productsQuery->orderBy('ratings_average', 'ASC');
break;
default:
$productsQuery = $productsQuery->orderBy('ratings_average', 'DESC');
}
$name=$request->input('productname');
$count=$request->input('country_id');
if(!empty($name)){
$productsQuery->where('productname', 'LIKE', '%'.$name.'%')->get();
}
if(!empty($count)){
$ProductsQuery->where('country_id', $request->input('country_id'))->get();
}
$products= $ProductsQuery->paginate(10);
藉口的情況下3和4 IM尚未進行編碼。