Support the ongoing development of Laravel.io →
Eloquent Database Routing
0
moderator

Hello @dushyant674

I see that you have an optional parameter in the route (the slug) but that it isn't optional in the controller action.

You can change that with adding a default value, example:

public function products($slug = '')
{
    dd($slug);
}

But to be honest I personal should split the route without a slug to another function then the url with a slug. And use the crud route names, see the documentation on https://laravel.com/docs/11.x/controllers#actions-handled-by-resource-controllers

0

Sign in to participate in this thread!

Eventy

Your banner here too?

Dushyant dushyant674 Joined 23 Dec 2024

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.