What's the best practice accessing $_GET values in Laravel?

流过昼夜 提交于 2019-12-19 20:00:06

问题


Is there a better way in accessing $_GET rather than the variable itself in Laravel or is that it?

I need multiple parameters for an API like /users?q=keyword&order=desc&limit=5

Is there a cleaner, safer and Laravel-ish way to access the $_GET values?

Thanks.


回答1:


You can use Input facade to reach those.

You can either do:

Input::all();

to retrieve all of the query parameters, or:

$q     = Input::get('q'); // will return 'keyword' for your example
$order = Input::get('order'); // will return 'desc' for your example
$limit = Input::get('limit'); // will return '5' for your example


来源:https://stackoverflow.com/questions/17759665/whats-the-best-practice-accessing-get-values-in-laravel

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