如何对多个对象数组使用 laravel FormRequest prepareForValidation 方法?
curl -i -X POST \
-H'Content-Type: application/json' \
-H'Accept: application/json'\
-H'Authorization: Bearer PLKKSDSDSD....'\
//array of objects
-d'[{
"account_id": "ABC",
},
{
"account_id": "DEF",
}]' \
https://domain/api/account
protected function prepareForValidation()
{
$account_id = $this->account_id;
$account = Account::select('id')->where('name', $account_id)->first();
$this->merge([
'account_id' => is_null($account) ? 0 : $account->id,
]);
}
当使用发布数据作为一个简单的对象时,我可以使用 prepareForValidation 作为一种魅力,但是当使用上面演示的对象数组时,我不知道该怎么做。
任何帮助将不胜感激。