skip to Main Content

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’);

2

Answers


  1. 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</>
    
    Login or Signup to reply.
  2. 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');
    
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search