Search code examples
laravelrouteshref

How to pass href with id to controller method Laravel


I have the following href function in my view and I have to attach a id ($group) to my route.

<a class="btn btn-primary btn-block" href="{{ route('show.invitation', {{$group}}) }}">Invite User to Group</a>

This is my web route.

Route::get('invitation/show{group}', 'InvitationController@show')->name('show.invitation');

I get this error message.

Missing required parameters for [Route: show.invitation] [URI: invitation/show/{group}]. (View: /Users/daniel/Documents/Development/Laravel/bolzer/resources/views/settinggroup/overview.blade.php)


Solution

  • first, edit your route

    Route::get('invitation/show/{group}', 'InvitationController@show')->name('show.invitation');
    

    with route() method, pass the name of the route

    <a href="{{ route('show.invitation', $group) }}" class="btn btn-primary">Invite User to Group</a>  
    

    with url() method, pass URL of the route

    <a href="{{ url('/invitation/show/', $group) }}" class="btn btn-primary">Invite User to Group</a>