Global Validation - Adding Multiple Rules?

Hi Guys,

For uploading files I’ve added a rule ro the php config/livewire.php file like so php 'file|mimes:png,jpg,jpeg,zip|max:100000'

This is fine, it works as expected.

The problem is, I have multiple file inputs on a form, some I want to accept images and another one I only want to accept zip files.

How can I add multiple rules within the config file to validate multiple inputs ?

Here’s my current temporary_file_upload config

'temporary_file_upload' => [
        'disk' => null,        // Example: 'local', 's3'              Default: 'default'
        'rules' => 'file|mimes:png,jpg,jpeg,zip|max:100000',       // Example: ['file', 'mimes:png,jpg']  Default: ['required', 'file', 'max:12288'] (12MB)
        'directory' => null,   // Example: 'tmp'                      Default  'livewire-tmp'
        'middleware' => null,  // Example: 'throttle:5,1'             Default: 'throttle:60,1'
        'preview_mimes' => [   // Supported file types for temporary pre-signed file URLs.
            'png', 'gif', 'bmp', 'svg', 'wav', 'mp4',
            'mov', 'avi', 'wmv', 'mp3', 'm4a',
            'jpeg', 'mpga', 'webp', 'wma'
        ],
    ],

Hi

On your form, are you saying you have a few different input boxes, one for jpeg and one for zip and one for pdf, as an example?

For validation, you would not validate in the config file, this would be done in the livewire controller file.

protected $rules = [
    'input1' => 'jpeg',
    'input2' => 'zip',
    'input3' => 'pdf',
];

public function save()
    {
        $this->validate();
    }

Hi,

Yes that’s correct. I’ve tried the “rules” within the controller and yes it validates, but it doesn’t prevent the temporary file being uploaded.

I receive the error message as expected but it still uploads the temporary file.