Один из моих API использует FormRequest, который выглядит следующим образом:
Код: Выделить всё
class StoreInvoiceRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*/
public function authorize(): bool
{
return match($this->method()) {
// Anyone can create new record
'POST' => true,
// Updating must match record owner
'PUT', 'PATCH' => $this->invoice->user_id === auth()->id(),
// Unauthorized for everything else
default => false,
};
}
/**
* Get the validation rules that apply to the request.
*/
public function rules(): array
{
return [
'customer_id' => ['required', Rule::exists('customers', 'id')->where(static function ($query) {
return $query->where('user_id', auth()->id());
})],
'customer_email_ids' => ['present', 'array'],
'customer_email_ids.*' => ['required', 'integer', Rule::exists('emails', 'id')->where(function ($query) {
return $query->where('customer_id', $this->input('customer_id'));
})],
];
}
public function bodyParameters(): array
{
return [
'customer_id' => [
'example' => 1,
],
'customer_email_ids' => [
'description' => 'Array of email IDs associated with the customer (who will receive email notifications)',
'type' => 'array',
'example' => [1, 2, 3],
],
];
}
}

Я пробовал разные методы, но ни один из них не работает, есть идеи?
Подробнее здесь: https://stackoverflow.com/questions/791 ... ormrequest