Martin Christopher
Martin Christopher

Reputation: 409

Laravel Routing URL

I want to make a routing on laravel {{ route('import',[$p->id]) }} this are on my a href but when my cursor hovering on the button it preview import?1 not import/2 what is my mistake here?

Upvotes: 0

Views: 119

Answers (3)

Dilip Hirapara
Dilip Hirapara

Reputation: 15296

You can define route as ->name('import') or 'as'=>'import' here.

Route::get('import/{id}','Controller@method')->name('import');

Or

Route::get('import/{id}',['as'=>'import','uses'=>'Controller@method']);

In href you can call as

<a href="{{ route('import',[$p->id]) }}">CLick</a>

If the named route defines parameters, you may pass the parameters as the second argument to the route function. The given parameters will automatically be inserted into the URL in their correct positions:

Route::get('user/{id}/profile', function ($id) {
    //
})->name('profile');

$url = route('profile', ['id' => 1]);

//Url will be domain.com/user/1/profile.

Upvotes: 1

Zain Farooq
Zain Farooq

Reputation: 2964

In routes you should name the routes and pass the parameters there as well. For example

Route::get('/import/{id}','AnyController@controllerFunction')->name('import');

Then in views you can call the route function as you did.

{{ route('import',[$p->id]) }}

Upvotes: 2

sss S
sss S

Reputation: 384

Try This

{{ route('import/'.$projects->id) }}

Upvotes: 0

Related Questions