error after deploy my laravel app to server my code works fine on my loacal machine but after upload it to the server i got this error
if($this->newimage)
{
if($this->image)
{
unlink('assets/images/profile/'.$this->image);
}
$imageName = Carbon::now()->timestamp . '.' . $this->newimage->extension();
$this->newimage->storeAs('profile',$imageName);
$user->profile->image = $imageName;
}
CodePudding user response:
The address of a file should be an absolute path. I don't know where is your assets
directory but in the case of being in your Laravel app root, this would be the solution:
unlink(base_path('assets/images/profile/'.$this->image));
CodePudding user response:
you can set your storage directory instead of public
$storePath = storage_path('app/public/'.$this->image);
if (file_exists($storePath)) {
Storage::disk('public')->delete($this->image);
}
CodePudding user response:
use the helper asset('path/to/file')
e.g.
if this is your image path public/assets/images/profile/1649308242.png.
unlink(asset('assets/images/profile').'/'.$this->image);