8

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
Andrew
  • 18,680
  • 13
  • 103
  • 118
s1njar
  • 123
  • 1
  • 1
  • 9

3 Answers3

22

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.

Nole
  • 796
  • 7
  • 11
2

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']);
Andrew
  • 18,680
  • 13
  • 103
  • 118
1

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

redirect()->with(['id' => 1]);
s1njar
  • 123
  • 1
  • 1
  • 9