s1njar
s1njar

Reputation: 123

Laravel 5.5 Blade route() parameter

Can I add a parameter which I can use in a blade template, and which doesn't appear in the url?

route("Home", ['id' => 1]);

@if(isset($id))
    //Do something
@endif

Upvotes: 8

Views: 84274

Answers (3)

Andrew
Andrew

Reputation: 20081

You can pass in parameters just like that yes, but they will be included in the url:

https://laravel.com/docs/5.5/routing#named-routes

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

To pass parameters without including them in the url you will need to add the parameters in the controller/router method, and not within the route() method. Eg:

Route::view('/welcome', 'welcome', ['name' => 'Taylor']);

Upvotes: 2

Nole
Nole

Reputation: 847

I had need to create route in view and to send parameter that route.

I did it this way:

{{route('test', $id)}}

This article helped me.

Upvotes: 22

s1njar
s1njar

Reputation: 123

I solved it. instead of route() is used redirect()

redirect()->with(['id' => 1]);

Upvotes: 1

Related Questions