简体   繁体   English

为什么request()辅助函数返回null

[英]Why request() helper function returns null

According episode 19 Laravel 5.4. 根据第19集Laravel 5.4。 from Scratch (time 4:53) from laracasts.com video, code request(['name', 'email', 'password']) should return array containing name, email and password from user registration form. 从laracasts.com视频的Scratch(时间4:53)开始,代码request(['name', 'email', 'password'])应返回用户注册表格中包含名称,电子邮件和密码的数组。

But in my case it returns null . 但就我而言,它返回null

I'm sure, form is ok because request()->only(['name', 'email', 'password']) works. 我敢肯定,形式是可以的,因为request()->only(['name', 'email', 'password'])有效。 It returns Array( [name] => awesomename [email] => email@email.com [password] => asdfadsf) properly. 它会正确返回Array( [name] => awesomename [email] => email@email.com [password] => asdfadsf)

What could be wrong? 有什么事吗

Look at the documentation for the helper: 查看帮助程序的文档:

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

It only gets the current request or obtains an input item. 它仅获取当前请求或获取输入项。 It does not accept an array as an argument. 它不接受数组作为参数。

$request = request();

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM