Save Photo With Livewire Hello everyone. I am using Laravel 10 and Livewire 3. I want to save my photo to app/public/images/brands folder. How ever it always save storage. When I can't use livewire I try;
$productPic = $request->file('productPic');
$imageName = $productPic->getClientOriginalName();
$productPic->move(public_path('publicImages/products'), $imageName);
and it works(this is my old code). Now I want to this with livewire but it not works. I see "change config/filesystem.php folder" but is there another way? I can't want to change any config change.
When I try to move(public_path('/images/brands/'), $logoName) this time it gives me error:
Could not move the file "/private/var/folders/0l/_l4sg1r170d9q50bc01qqppw0000gn/T/phpR3qnAp" to "/Users/onurozdogan/Documents/GitHub/izka.com/public/images/brands/man.png" ().
What else does the error message report?
@tykus This is my all error. It point here $this->brandLogo->move(public_path('/images/brands/'), $logoName); and my function:
public function addBrand()
{
$this->validate();
$logo = $this->brandLogo->path();
$logoName = $this->brandLogo->getClientOriginalName();
$this->brandLogo->move(public_path('/images/brands/'), $logoName);
dd('test');
$brand = new Brands();
$brand->name = $this->brandName;
$brand->logo = $this->brandLogo->getClientOriginalName();
$brand->save();
session()->flash('message', 'Marka başarıyla eklendi.');
return redirect()->route('admin.brands');
}
@onurzdgn is the destination writable by the web server?
@tykus Yes. I did this from blade without livewire.
@onurzdgn can you share the entire Livewire Component class?
@tykus
<?php
namespace App\Livewire\Admin;
use App\Models\Brands;
use Livewire\Component;
use Livewire\WithFileUploads;
class AddBrand extends Component
{
use WithFileUploads;
public $brandName, $brandLogo;
public function rules()
{
return [
'brandName' => ['required', 'unique:brands,name'],
'brandLogo' => ['required', 'image', 'mimes:jpg,jpeg,png', 'max:1024']
];
}
public function messages()
{
return [
'brandName.required' => 'Marka adı olmadan olmaz.',
'brandName.unique' => 'Bu marka adını kullandın. Nasıl hatırlamazsın?',
'brandLogo.required' => 'Marka logosu eklemzsen nasıl olacak?',
'brandLogo.image' => 'Marka logosu resim formatında olmalı.',
'brandLogo.mimes' => 'Marka logosu jpg, jpeg veya png formatında olmalı.'
];
}
public function render()
{
return view('livewire.admin.add-brand');
}
public function addBrand()
{
$this->validate();
$logo = $this->brandLogo->path();
$logoName = $this->brandLogo->getClientOriginalName();
$this->brandLogo->move(public_path('/images/brands/'), $logoName);
dd('test');
$brand = new Brands();
$brand->name = $this->brandName;
$brand->logo = $this->brandLogo->getClientOriginalName();
$brand->save();
session()->flash('message', 'Marka başarıyla eklendi.');
return redirect()->route('admin.brands');
}
}
Please sign in or create an account to participate in this conversation.