Laravel 检查输入 isset

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26550009/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 10:19:37  来源:igfitidea点击:

Laravel checking input isset

phplaravel

提问by Yada

Laravel Input helper has

Laravel 输入助手有

Input::has('debug')

输入::已('调试')

My problem is that I often use query parameter without the value such has http://example.com?debug

我的问题是我经常使用没有http://example.com?debug这样的值的查询参数

The problem is that Input::has('debug') will return false in this case because there is no value. ie. debug=1

问题是 Input::has('debug') 在这种情况下将返回 false,因为没有值。IE。调试=1

So I end up having to use isset($_GET['debug']).

所以我最终不得不使用isset($_GET['debug']).

Is there a laravel way to check whether the input isset?

有没有laravel方法来检查输入是否为isset?

回答by Razor

In this case, use existsmethod:

在这种情况下,使用exists方法:

// http://example.com?debug
var_dump(app('request')->exists('debug')); // return true

// http://example.com
var_dump(app('request')->exists('debug')); // return false