You get undefined variable where?
Jul 16, 2017
12
Level 1
"Undefined variable: sort"
I want to order products by price and I have some issues, I have this route:
Route::get('shop/{category_url}/','SortController@sort')
controller:
public function sort( $category ,Request $request )}
if ($category1 = Categorie::where('url', '=', $category)->first()) {
$sort = $request->get('sort', 'asc');
$products = Product::where('categorie_id', $category1->getAttribute('id'))-orderBy('price', $sort)->get();
$sort = $sort == 'asc' ? 'desc' : 'asc'; // to use in sort link
return view('content.products', compact('products', 'sort'));
}
}
view:
@if ($category)
<h2 class="text-center">{{$category['title']}} </h2>
<center>
<a href="{{ url('shop/'.$category['url'])}}?sort={{$sort}}">Sort {{$sort === 'asc' ? 'ascending' : 'descending'}}</a>
right now I got an error "Undefined variable: sort" I want to create 2 link one to ASC and the other for DESC
Please or to participate in this conversation.