2017-06-15 26 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