2017-06-15 27 views
0

根据第19集Laravel 5.4。从laracasts.com视频的Scratch(时间4:53)开始,代码request(['name', 'email', 'password'])应该从用户注册表单返回包含姓名,电子邮件和密码的数组。为什么request()帮助函数返回null

但在我的情况下,它返回null

我敢肯定,窗体是好的,因为request()->only(['name', 'email', 'password'])的作品。它正确返回Array([name] => awesomename [email] => [email protected] [password] => asdfadsf)

什么可能是错的?

回答

0

看看在助手的文档:

https://laravel.com/docs/5.4/helpers#method-request

只获取当前请求或者获得一个输入项。它不接受一个数组作为参数。

$request = request(); 

$value = request('key', $default = null) 
+0

我知道。这就是为什么我不了解视频的原因。它是错误吗? – Miloslav21

+0

不,你只是不正确地使用帮手。该方法签名只允许一次传递一个密钥。 – btl

+0

请观看[https://laracasts.com/series/laravel-from-scratch-2017/episodes/19?autoplay=true](https://laracasts.com/series/laravel-from-scratch-2017/episodes/19?autoplay = true),时间4:53 – Miloslav21