Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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)?

like image 555
Andrea Avatar asked Jul 09 '15 17:07

Andrea


People also ask

How do I find the parameter of a URL?

For getting the URL parameters, there are 2 ways: By using the URLSearchParams Object. By using Separating and accessing each parameter pair.

What is source parameter in URL?

What Are URL Parameters? Also known by the aliases of query strings or URL variables, parameters are the portion of a URL that follows a question mark. They are comprised of a key and a value pair, separated by an equal sign. Multiple parameters can be added to a single page by using an ampersand.

How to get current URL or path in blade file?

So now they are all methods of Request and also can be called statically in Blade file without a problem. So get current url or path in blade by using Request method. So the methods we can use for this are Request::url (), or Request::fullUrl (), or Request::path (), Request::is () and also Request::segment ().

How to get current URL in a blade view in Laravel?

So here the following examples to laravel by get current url in a blade view: By using the Request::path () method to get current path. Now here by using the Request::url () method. It will return us the entire URL, but strip the query string from it. here using the Request::is () method.

How to get parameter form Uri in lumen from Laravel request?

There are some conventional ways in Laravel doesn't work on Lumen. And get parameter form URI in middleware is one of them. In Laravel, I just need to call $request->id, it will work like magic. But here in order to get parameter in Lumen, I need to do something like this:


2 Answers

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/

like image 123
Andrea Avatar answered Sep 27 '22 17:09

Andrea


The shortest way i have used

{{ Request::get('a') }} 
like image 37
Hai Nguyen Avatar answered Sep 27 '22 16:09

Hai Nguyen