How to get URL parameter in a Laravel Blade view
In Laravel, you can retrieve URL parameters in a Blade view using the request
helper method.
For example, if your URL looks like this: http://example.com/products?id=123
, you can retrieve the id
parameter in your Blade view using the following code:
{{ request('id') }}
This will output the value of the id
parameter, which is 123
in this case.
You can also provide a default value in case the parameter is not present in the URL:
{{ request('id', 'default') }}
This will output default
if the id
parameter is not present in the URL.
Alternatively, you can use the input
method to retrieve URL parameters:
{{ request()->input('id') }}
Both request('id')
and request()->input('id')
are equivalent and will produce the same result.