Home > Enterprise >  Laravel, get id from an <a> link
Laravel, get id from an <a> link

Time:12-01

How to get user id properly?, This is error message Missing required parameter for [Route: user.currentRequest] [URI: user/user-current-request/{user}] [Missing parameter: user]

An User has many relationship with Request, and the url will be user-current-request{user-id}

//layouts.app

<li class="nav-item">
    <a class="nav-link" href="{{ route('user.currentRequest') }}">Current Request</a>
</li>
Route::group(['prefix'=>'user', 'middleware'=>['isUser','auth']], function(){

    Route::get('user-current-request/{user}', [UserController::class, 'currentRequest'])->name('user.currentRequest');
});
    function currentRequest(User $user)
    {
        dd($user);

        return view('dashboards.users.currentRequest');
    }

CodePudding user response:

Your route in Layouts.app need params.

<li class="nav-item">
    <a class="nav-link" href="{{ route('user.currentRequest', $user) }}">Current Request</a>
</li>

If you want to give this params in layout you have to do it in the providers / appserviceprovider

  • Related