@rafaelmunoznl do you tried Storage::disk('public')->delete($request->avatar_location);?
Delete files from storage
I am using the storage directory to uploa the avatars of my users.
The structure is like this: storage/app/public/avatars/file.jpg
I am able to upload avatars without problem, but when the user decides to change the avatar, I need of course, to delete the previous avatar. i have been trying to implement the method described here: https://laravel.com/docs/5.8/filesystem#deleting-files.
I did this:
<?php
namespace App\Models\Client\Traits\Method;
...
use Illuminate\Support\Facades\Storage; // <- Call the facade
...
trait ClientMethod
{
public static function getPicture($request, $size = false)
{
Storage::delete($request->avatar_location); //<- here I intend to delete the file in https://mydomain.com//storage/avatars/rasputin-1583231825.png
// more code here
}
}
The file exist in that location. I can download it. Everything looks like the documentation, but it does not get deleted.
Am I missing something?
@rafaelmunoznl you should pass the path (avatars/misi1-1583236599.jpg) from the database to delete method and not the full URL.
Please or to participate in this conversation.