0

I am working with livewire in my laravel project. Image uploading is not working properly when i select image it gives error on the first call. I'm attaching the error's image as for reference.

Error Image

I have pasted My component code below for reference.

brands.php

<?php

namespace App\Http\Livewire;
use Livewire\WithFileUploads;

use Livewire\Component;

class Brands extends Component
{
    use WithFileUploads;
    public $title;
    public $description;
    public $image;

    protected function rules()
    {
        return [
            'title' => 'required|max:255',
            'image' => 'required|image|max:1024', // 1MB Max
        ];
    }

    public function updated($fields)
    {
        $this->validateOnly($fields);
    }
    public function submit() {
        $this->validate();
        dd($this->title, $this->description, $this->image);
    }
    public function render()
    {
        return view('livewire.brands');
    }
}

brands.blade.php

<form wire:submit.prevent="submit" enctype="multipart/form-data">
 <h3 class="modal-delete-heading">Add Brand</h3>
    <div class="row">
            <div class="col-md-12">
                <div class="upload-brand">
                    <div class="qust-filed">
                        <div class="form-control d-flex align-items-center justify-content-center">

                            <input name="image" type='file' id="imageUpload" accept=".png, .jpg, .jpeg" class="input-file d-none" wire:model="image" />
                            @error('image') <span class="text-danger">{{ $message }}</span> @enderror
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-md-12">
                <div class="input-style-ctm">
                    <label class="d-block">{{ __('Title') }} <span class="text-danger">*</span></label>
                    <input type="text" name="title" class="ctm-input" wire:model="title" />
                    @error('title') <span class="text-danger">{{ $message }}</span> @enderror
                </div>
            </div>

            <div class="col-md-12">
                <div class="input-style-ctm">
                    <label class="d-block"> {{ __('Description') }}</label>
                    <input type="text" name="description" class="ctm-input" wire:model="description" />
                    @error('description') <span class="text-danger">{{ $message }}</span> @enderror
                </div>
            </div>
    </div>

0 Answers0