0

UserRequest

<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class EmployeeRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array<string, mixed>
     */
    public function rules()
    {
        return [
            'first_name'=>'required|string',
            'last_name'=>'required|string',
            'email'=>'required|email|unique:employees,email',
            'contact_number'=>'required|numeric',
            'date_of_birth'=>'required',
            'current_address'=>'required',
            'pan_number'=>'required|numeric',
            'bank_account_number'=>'required',
            'avatar'=>'required|image|mimes:jpeg,png',
            'documents'=>'required',
            'documents.*'=>'max:5000|mimes:pdf,png,jpeg',
        ];
    }
    public function messages()
    {
      return [        
        'avatar.image'=> "Invalid image format",    
        'documents.max' => "Error uploading file:File too big.Max file size:5MB",
      ];
    }
}

I am trying to create an API where when a user enters a file/n number of files or image whose size is more than 5MB I want to throw a custom validation message but it shows Warning: POST Content-Length of 16043214 bytes exceeds the limit of 8388608 bytes in Unknown on line in postman. Does anyone have any idea regarding this? I am using docker to run the server and any help will be really appreciated.

  • Basically, the file you're uploading looks to be 16MB, but the max your **server** accepts is 8MB. Your validation is enforcing 5MB limit, but the server maximum is _also_ being exceeded, which short-circuits your Laravel validation. Either A) increase your validation limit to 8 MB as well, or B) lower your server limit to 5MB (or slightly more, to allow "wiggle-room" for the Validation to trigger). – Tim Lewis Aug 09 '22 at 18:49
  • Or C) upload a file that is between 5MB and 8MB; that would trigger the validation, but not trigger your server limit warning. – Tim Lewis Aug 09 '22 at 18:56

0 Answers0