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
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
I had need to create route in view and to send parameter that route.
I did it this way:
{{route('test', $id)}}
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']);
I solved it. instead of route()
is used redirect()
redirect()->with(['id' => 1]);