Reputation: 1353
i have a foreach with my list of products in my index.blade.php, it work well, now i'm tryng to filter, i done my menu with my categories and genders.
I would like show products with category = "t-shirt" and gender= "woman" but i have this error:
ErrorException in StoreController.php line 36: Missing argument 1 for dixard\Http\Controllers\StoreController::products()
i'm using this link:
<a href="{{url('shop', ['category'=> 't-shirt', 'gender' => 'woman'])}}" title="">
<span>Woman</span>
</a>
my route:
Route::get('shop', 'StoreController@index');
Route::get('shop/{category}/{gender}','StoreController@products');
My controller
public function products($category, $gender)
{
$gender_id= Gender::where('gender', $gender )->first();
$category_id= Category::where('name', $category)->first();
$filter = ['gender_id' => $gender_id->id, 'category_id' => $category_id->id];
$products = Product::where($filter)->orderBy('id', 'asc')->get();
$categories = Category::all();
return view('store.index', compact('products','categories'));
}
Upvotes: 0
Views: 103
Reputation: 1353
i fixed like this:
Route::get('shop','ShopController@index');
Route::get('shop/{categoryA}','ShopController@category');
Route::get('shop/{categoryB}/{genderB}','ShopController@categoryGender');
Route::get('shop/{categoryC}/{genderC}/{slugC}','ShopController@product');
I dont know why but i changed that of variables that i pass to my route and it work!
Upvotes: 0
Reputation: 4690
You can use named routes. There's nothing special with this.
Route::get('shop/{category}/{gender}', [
'uses' => StoreController@products',
'as' => 'shopRoute'
]);
And your URL:
route('shopRoute', ['category'=> 't-shirt', 'gender' => 'woman'])
Upvotes: 1
Reputation: 90
Use the route function (https://laravel.com/docs/5.1/routing)
<a href="{{route('shop', ['category'=> 't-shirt', 'gender' => 'woman'])}}" title="">
<span>Woman</span>
</a>
Upvotes: 0