Lumen: get URL parameter in a Blade view
I'm trying to get a url parameter from a view file.
I have this url:
http://locahost:8000/example?a=10
and a view file named example.blade.php
.
From the controller I can get the parameter a
with $request->input('a')
.
Is there a way to get such parameter from the view (without having to pass it from the controller to the view)?
This works well:
{{ app('request')->input('a') }}
Where a
is the url parameter.
See more here: http://blog.netgloo.com/2015/07/17/lumen-getting-current-url-parameter-within-a-blade-view/
The shortest way i have used
{{ Request::get('a') }}
Given your URL:
http://locahost:8000/example?a=10
The best way that I have found to get the value for 'a' and display it on the page is to use the following:
{{ request()->get('a') }}
However, if you want to use it within an if statement, you could use:
@if( request()->get('a') )
<script>console.log('hello')</script>
@endif
More simple in Laravel 5.7 and 5.8
{{ Request()->parameter }}