I am newbie to laravel and i am working on a project and i have a following situation
lets assume my base url is https://example.com
Now i want to pass a slug(argument) after a base url which means https://example.com/xyz something like that, and i need to do this on multiple times in my project
This is what i’d tried but it is not working it says that route is not defined.
Route::get('{slug?}', [AppHttpControllersUiviewsController::class, 'method1'])->name('method1');
Route::get('/method2/{slug?}', function($slug){
return redirect()->route('method1', ['slug'=>$slug]);
});
And also how can i achieve that on which argument which particular method should be called? for example if i have several other routes similar to above one.
how can i achieve this?
Thank you in advance for your help. 🙂
2
Answers
You should use the
fallback
system.Laravel Route fallback official docs
also, beware:
Other Option:
Also, you can define a parameter as below example
Please Try php artisan route:cache in your terminal then check it again.