skip to Main Content

I have following routes in my routes/web.php.

Route::get('page/{slug}', 'PageController@index')->name('front.page.slug');
Route::get('inquiry/contact-us', 'ComplaintController@index')->name('front.complaint');
Route::get("product/{product}", 'ProductController@show')->name('front.get.product');

Its working e.g.

when i change my routes it showing me error that product doesn’t exit in page model.

Route::get('{slug}', 'PageController@index')->name('front.page.slug');
Route::get('contact-us', 'ComplaintController@index')->name('front.complaint');
Route::get("{product}", 'ProductController@show')->name('front.get.product');

i have no idea how to start routes with slugs without resource name for SEO friendly URLs E.g.

3

Answers


  1. Route::get('{slug}', 'PageController@index')->name('front.page.slug');
    Route::get('contact-us', 'ComplaintController@index')->name('front.complaint');
    

    If you do like that. contact-us page execute in front.page.slug route.

    You can not use two variable in route file.

    Make like this:

    Route::get('contact-us', 'ComplaintController@index')->name('front.complaint');
    Route::get('{slug}', 'WebController@index')->name('front.page.slug');
    

    and determine {slug} ‘s category in controller. Is page or is product? Do this in same controller. Otherwise just first {} works in route file.

    Login or Signup to reply.
  2. laravel does not consider {slug} and {product} as two different routes

    Login or Signup to reply.
  3. you can do it like this example:

    Route::get('page-{slug}', 'PageController@index')->name('front.page.slug');
    Route::get('contact-us', 'ComplaintController@index')->name('front.complaint');
    Route::get("product-{product}", 'ProductController@show')->name('front.get.product');
    

    you should consider a diffrence between two route.

    {product} and {slug} are the same

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search