anichur's avatar

Image uploading problem in laravel livewire

Hello everyone, I am a newbie in laravel livewire. Recently I am working on a project where I need to save user photos with other data using livewire. But when I submit the form, then the following error occurred. C:/Users/Anis/AppData/Local/Temp/phpE8A0.tmp 404 (Not Found)

Here is my frontend code:

And here is the backend code: use WithFileUploads;
public $fullnames,$email,$gender,$mobile_number,$joining_date;
public $currency,$address,$country;
public $user_photo;

protected $rules = [

    'fullnames' => 'required',
    'email' => 'required|email|unique:users',
    'mobile_number' => 'required|min:11|max:11',
    'joining_date' => 'required',
    'address' => 'required|min:20'
];
public function __construct()
{
    $this -> countries = countries();
    $this -> image = 'assets/default_photo.jpg';
}

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

Please help me. Thanks in advance.

0 likes
1 reply
Nakov's avatar

Use mount() instead of __construct() in a livewire component is my first suggestion..

I cannot see any upload that happens in your code. There is a very good documentation on how to do it btw, so take a look: https://laravel-livewire.com/docs/2.x/file-uploads

So you would want to do this:

$path = $this->image->store('photos');

// then store the $path in your database

Please or to participate in this conversation.