阅读(668) (0)

Laravel 8 获取部分输入数据

2021-06-24 11:31:31 更新

如果需要获取输入数据的子集,你可以使用 onlyexcept 方法。它们接受单个 array 或者动态参数列表:

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

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

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

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

技巧:only 方法返回请求中的全部键值对;但是它不返回请求中不存在的键值对。