laravel 中 get() 和 all() 的区别

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15362252/
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 07:36:55  来源:igfitidea点击:

Difference between get() and all() in laravel

phplaravellaravel-4

提问by Muhammad Raheel

What is difference between these two in laravel

这两者在 Laravel 中有什么区别

$input = Input::get();

And

$input = Input::all();

And which one i should prefer.

我应该更喜欢哪一个。

回答by juco

Taken from the laravel source:

取自 Laravel 源:

public static function all()
{
   $input = array_merge(static::get(), static::query(), static::file());
   // ....
   return $input;
}

So all()calls get()and returns it's contents along with query(), and file()the $_FILES superglobal.

所以all()通话get()和沿回报它的内容query(),并file()在$ _FILES超级全局。

Preference will obviously depend on circumstance. I personally choose to use Input::get($key, $default)as I usually know what I am after.

偏好显然取决于情况。我个人选择使用,Input::get($key, $default)因为我通常知道我在追求什么。

回答by Grant

From the Laravel Manual: http://laravel.com/docs/input

来自 Laravel 手册:http://laravel.com/docs/input

Retrieve a value from the input array:

从输入数组中检索一个值:

$email = Input::get('email');

Note: The "get" method is used for all request types (GET, POST, PUT, and DELETE), not just GET requests.

注意:“get”方法用于所有请求类型(GET、POST、PUT 和 DELETE),而不仅仅是 GET 请求。

Retrieve all input from the input array:

从输入数组中检索所有输入:

$input = Input::get();

Retrieve all input including the $_FILES array:

检索所有输入,包括 $_FILES 数组:

$input = Input::all();

By default, null will be returned if the input item does not exist. However, you may pass a different default value as a second parameter to the method:

默认情况下,如果输入项不存在,将返回 null。但是,您可以将不同的默认值作为第二个参数传递给该方法: