Devmasta
Devmasta

Reputation: 563

Laravel resource give extra parameter to route

I'm trying to access function in controller using wild cards in route through get call. The route is defined on this way:

Route::get('/somefunc/{alias1}/{alias2}', 'uses'=>'MyController@myfunction']);

The route link I'm trying to access is defined here:

<a href="{{'somefunc/somealiashere/'.$item->id }}" class="btn btn-primary">{{ __('Click') }}</a>

But when I click on the link it gives me extra parameter in the route:

items/somefunc/somealiashere/1 

because of the previous resource define in the web.php.

How to skip that 'items' parameter in the route.

Thank you.

Upvotes: 1

Views: 240

Answers (1)

Dilip Hirapara
Dilip Hirapara

Reputation: 15296

Try to use url()

<a href="{{ url('somefunc/somealiashere/'.$item->id) }}" class="btn btn-primary">{{ __('Click') }}</a>

Another way I recommend you is give name route.

Route::get('/somefunc/{alias1}/{alias2}', 'uses'=>'MyController@myfunction'])->name('somefunc');

and call it below.

<a href="{{ route('somefunc',['alias1'=>'somealiashere','alias2'=>$item->id]) }}" class="btn btn-primary">{{ __('Click') }}</a>

Upvotes: 2

Related Questions