Home > Net >  How to set custom route name before main route in Laravel?
How to set custom route name before main route in Laravel?

Time:11-27

I want to add username before each route..

ex:

sam/productDashboard

james/productDashboard

note - Username is getting from session.

i tried like this. it doesn't work

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

CodePudding user response:

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</>

CodePudding user response:

it registered on the start you can't do in this way

You could set it like params

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

  • Related