1
Route::get('/products/{page?}', 'ProductController@index')->name('products');
Route::get('/products/{category}/{page?}', 'ProductController@index')->name('products');

I created a two routes.

First one for all products, other for categories.

I got an error:

Missing required parameters for [Route: products] [URI: products/{category}/{page?}].

It is laravel: 5.5

I am calling all products like this:

{{ route('products') }}
3
  • 1
    You have two routes named products. That's going to cause an issue. Routes should have unique names. Commented Oct 14, 2019 at 12:26
  • two routes cannot have same names try changing the name of the routes Commented Oct 14, 2019 at 12:29
  • your routes will follow only first one Commented Oct 14, 2019 at 13:19

3 Answers 3

1

Change your route name like

Route::get('/products/{page?}', 'ProductController@index')->name('products');
Route::get('/products/{category}/{page?}', 'ProductController@index')->name('product.category');

For Product route:

{{ route('products') }}

For category route:

{{ route('product.category') }}
Sign up to request clarification or add additional context in comments.

1 Comment

@Nevermore You should use like {!! route('products', ['page' => $prev] ) !!}
0

Your route naming clashes, you will need to give your routes unique names.

Route::get('/products/{page?}', 'ProductController@index')->name('products.page');
Route::get('/products/{category}/{page?}', 'ProductController@index')->name('products.category.page');

Call the route with the new name.

{{ route('products.page') }}

If you want to get the route for for the route with the category parameter.

{{ route('products.category.page', $category) }}

Comments

0

Two routes cannot have same names and you are doing this. Change your routes name to:

Route::get('/products/{page?}', 'ProductController@index')->name('products');
Route::get('/products/{category}/{page?}', 'ProductController@index')->name('category.products');

and then you can call te routes like:

{{ route('products') }}
{{ route('category.products', ['category' => $category->id) }}

Thanks.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.