Laravel 8 獲取部分輸入數(shù)據(jù)

2021-07-16 18:04 更新

如果需要獲取輸入數(shù)據(jù)的子集,你可以使用 onlyexcept 方法。它們接受單個(gè) array 或者動態(tài)參數(shù)列表:

$input = $request->only(['username', 'password']);

$input = $request->only('username', 'password');

$input = $request->except(['credit_card']);

$input = $request->except('credit_card'); 

技巧:only 方法返回請求中的全部鍵值對;但是它不返回請求中不存在的鍵值對。

以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號