this is my url
http://project.dev/blogs/image-with-article
so, here I need the parameter image-with-article
in my blade to display which is a parameter named slug here is in my routes file I need the slug paramter in blade.
Route::get('/blogs/{slug}', ['as'=>'blog.by.slug', 'uses'=> 'CmsController@show']);
In Laravel 8, you can simply use request()->route('parameter_name') .
Laravel routes are located in the app/Http/routes.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. By convention, the Controller function accepts parameters based on the parameters provided.
The Default Route Files 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.
@JoelHinz I wouldn't call Request::route () logic - it seems pretty standard for Laravel. If you want to get the parameters without using the controller method This doesn't work; it returns empty. dd (request ()->query ('testing')) works though. In Laravel 8, you can simply use request ()->route ('parameter_name').
When injecting a model ID to a route or controller action, you will often query the database to retrieve the model that corresponds to that ID. Laravel route model binding provides a convenient way to automatically inject the model instances directly into your routes.
Laravel route model binding provides a convenient way to automatically inject the model instances directly into your routes. For example, instead of injecting a user's ID, you can inject the entire User model instance that matches the given ID.
Sometimes we may require to get route parameters value in our middleware like if you want to check permission etc. You can get easily using request object, that provide route method and you can get it. I also added small example that way you can undestand very well.
I'm not sure what you mean. If you're trying to construct the route in a Blade template, use
<a href="{{ route('blog.by.slug', ['slug' => 'someslug']) }}">...</a>
If you're trying to access the given parameter, I would suggest passing it from the controller:
// CmsController
public function show($slug)
{
// other stuff here
return view('someview', compact('slug'));
}
// someview.blade.php
{{ $slug }}
And if you really need to access the parameter from the view without first sending it from the controller... you really shouldn't, but you can use the facade:
{{ Request::route('slug') }}
If you want to get the parameters without using the controller method
{{dd(request()->route()->parameters)}}
In Laravel 8, you can simply use request()->route('parameter_name')
.
Easy way Just
{{ dd(request()->query("PARAMNAME")) }}
for get all PARAMs
{{ dd(request()->query()) }}
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