小编Irs*_*han的帖子

如何在 Laravel 中查看 API 的验证消息?

我正在使用 Laravel 8 并致力于 API 的开发。我已经创建了用于表单验证的请求类,但是当移动开发人员点击 API 验证消息时,未按要求显示。这是我的控制器方法:

 public function store(InvoiceStoreRequest $request)
{
    try {
        return $this->responseWithSuccess(true,'Invoice Data',
               $this->invoiceInterface->store($request), Response::HTTP_OK);
    }catch (\Exception $exception){
        return $this->responseWithError($exception->getMessage(),Response::HTTP_OK);
    }
}
Run Code Online (Sandbox Code Playgroud)

这里我使用InvoiceStoreRequest类来验证表单。代码InvoiceStoreRequest如下:

public function rules()
{
    return [
        'id' => ['required', 'string'],
        'invoice_date' => ['required', 'date'],
        'reference_number' => ['required'],
        'vendor_id' => ['required'],
        'invoice_net_total' => ['required','regex:/^\d*(\.\d{1,2})?$/'],
        'invoice_tax_total' => ['required', 'regex:/^\d*(\.\d{1,2})?$/'],
        'invoice_gross_total' => ['required', 'regex:/^\d*(\.\d{1,2})?$/'],
        'item_count' => ['required', 'numeric'],
        'invoice_type' => ['required','regex:(order|refund)'],
        'provider' => ['required'],
        'detail_url' => ['required'],
        'invoice_photo_url' => ['required'],
    ]; …
Run Code Online (Sandbox Code Playgroud)

php laravel

6
推荐指数
2
解决办法
5210
查看次数

标签 统计

laravel ×1

php ×1