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],
],
];
}
}
При создании документации API описание и пример из bodyParameters не используются, а вместо этого генерируется следующее:< /p>
Я пробовал разные методы, но ни один из них не работает, есть идеи?
Я документирую свой API Laravel с помощью Scribe Один из моих API использует FormRequest, который выглядит следующим образом: [code]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], ], ]; } } [/code] При создании документации API описание и пример из bodyParameters не используются, а вместо этого генерируется следующее:< /p> [img]https://i.sstatic.net/oWZalA4i.png[/img] Я пробовал разные методы, но ни один из них не работает, есть идеи?