nagm_star's avatar

How to delete image from folder after delete post

show this error "unlink(): http does not allow unlinking"

this is function


    public function kill(post $post , $id)
    {

        $post = Post::withTrashed()->where('id', $id)->firstOrFail();
        //dd($post);

        if($post->trashed()) {

            unlink($post->featured);
            $post->forceDelete();
        } else {

            $post->delete();
        }
        session()->flash('success', 'Post Deleted successfully');

        return redirect(route('posts.trashed'));


    }

0 likes
7 replies
janosk's avatar

One easy way is to use the storage facade. And i would do it before deleting the post.

use Illuminate\Support\Facades\Storage;

Storage::delete($post->featured);
Snapey's avatar

What form is $post->featured ? it needs to the the filepath not the URL to the image.

nagm_star's avatar

i used this to store image

        $featured = $request->featured;
        $featured_new_name = time().$featured->getClientOriginalName();
        $featured->move('uploads/posts', $featured_new_name);
Snapey's avatar

can't you just look in the database and give an example filename. This still does not tell us what $post->featured contains?

Snapey's avatar

I know..... what does it contain?

Please or to participate in this conversation.