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
In Laravel 8, you can simply use request()->route('parameter_name') .
A parameter provided in the route is usually annotated with curly braces. For instance, to pass in a name parameter to a route, it would look like this. Route::get('/params/{name}', function ($name) { return $name }); By convention, the Controller function accepts parameters based on the parameters provided.
All Laravel routes are defined in your route files, which are located in the routes directory. These files are automatically loaded by your application's App\Providers\RouteServiceProvider . The routes/web.php file defines routes that are for your web interface.
You can also use Route::current()->getName() to check your route name.
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.
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 withing the route()
method. Eg:
Route::view('/welcome', 'welcome', ['name' => 'Taylor']);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With