Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to set custom route name before main route in Laravel?

I want to add username before each route..

ex:

sam/productDashboard

james/productDashboard

note – Username is getting from session.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

i tried like this. it doesn’t work

Route::get( session()->get(‘name’).’/productDashboard’,[ProductController::class,’ProductDashboard’])->name(‘productDashboard’);

>Solution :

This is not the way to use variable inside a route.
Do it like this:

Route::get('{username}/productDashboard',[ProductController::class,'ProductDashboard'])->name('productDashboard');

and when you are referencing to this route with a link do it this way:

<a href="{{route('productDashboard',['username' => session()->get('name')])}}">Link</>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading