Laravel How to Isset _GET

匿名 (未验证) 提交于 2019-12-03 01:05:01

问题:

I'm still very new at Laravel.

I got problem how can I use Isset($_GET)?

How to get for example: http://virtualhost.com/flytrap/public/location?city=25?

Usually when at pure PHP, I always use:

if (isset($_GET["submit"])) {    $location = $_GET["city"]; } 

to get city value. So I can use it for query at database. If I use Core PHP method I got an error.

回答1:

You can use below code

$location = Request::query('city', false); //insed of $_GET['city']; 


回答2:

This is Laravel equivalent (see http://laravel.com/docs/4.2/requests):

if (Input::has('submit')) {     $location = Input::get('city'); } 

But as Lalit Sharma says, you should maybe always set $location even if you have not "submit" in GET:

$location = Input::get('city', null); 

null is the default value so you can ommit it or use any other value:

$location = Input::get('city', 'Reykjavik'); 


易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!