Apr 22, 2021
0
Level 6
This is how to upload image in livewire
In case you have problem.
public function store(){
$action = '';
$data = $this->validate([
'product_image' => 'image|max:1024',
'product_name' => 'required',
]);
if(!empty($this->product_image)){
$product_image = 'product_image.' . time() . $this->product_image->getClientOriginalName();
$this->product_image->storeAs('public/images', $product_image);
$data['product_image'] = $product_image;
}
if($this->productId){
Product::find($this->productId)->update($data);
$action = 'edit';
}else{
Product::create($data);
$action = 'store';
}
$this->emit('showEmitedFlashMessage', $action);
$this->resetInputFields();
$this->emit('refreshParent');
$this->emit('closeProductModal');
}
I also run php artisan storage:link.
Please or to participate in this conversation.