Laravel Livewire default rules taking precedence over explicitly defined rules - Hack The Tech - Latest News related to Computer and Technology

Hack The Tech - Latest News related to Computer and Technology

Get Daily Latest News related to Computer and Technology and hack the world.

Saturday, September 30, 2023

Laravel Livewire default rules taking precedence over explicitly defined rules

I am using Laravel v10.25.2 and Livewire v3.0.5.

I am trying to use the File Uploads in my component:

class CaseNew extends Component
{
    use WithFileUploads;
.../

I am trying to validate the file input with custom rules applied on the component property:

public function updatedAttachments()
    {
        $this->resetValidation();
        $this->validate([
            'attachments.*' => 'file|array:5|mimes:png,jpg,jpeg,gif,zip,pdf,docx,xlsx,txt,heic|max:11000'
        ]);
    }

I have also tried the same approach like this:

#[Rule(['attachments.*' => 'file|max:11000|mimes:png,jpg,jpeg,gif,zip,pdf,docx,xlsx,txt,heic'])]
public $attachments = [];

However, when I try to test it and attach a file that is bigger than 11000 KB, I get the error in my blade that the file size exceeds 12288 KB, which is Livewire's default size. It seems no matter which way I try to do this, I get the same error matching the default value, not the value I specify in my rules.

Now I can set the default value in my config/livewire.php file, but shouldn't setting the rule like above override that? If I happen to implement file upload in different parts of my site, that have their own requirements, the general rules cannot cover them all in that case. Am I doing something wrong in my process or missing something else?



source https://stackoverflow.com/questions/77203685/laravel-livewire-default-rules-taking-precedence-over-explicitly-defined-rules

No comments:

Post a Comment