Laravel spatie/medialibrary addToCollection not working

Posted 3 months ago by Dronax

I have a post model and registered collection and conversions of images the post:

public function registerMediaCollections()

public function registerMediaConversions(Media $media = null)

When I save image in controller with:

public function store(AddEditPostRequest $request)
    $post = Post::create($request->except(['banner', 'cover']));
    if ($request->banner) {
        $filename = md5($request->banner) . $request->banner->getClientOriginalExtension();


    if ($request->cover) {
        $filename = md5($request->cover) . $request->cover->getClientOriginalExtension();


    return redirect()->route('posts.index', $post);

Medialibrary save images on incorrect path. I have storage folder. And he's not create new folder posts. Why? I get this structure of folder storage: enter image description here Folders: 1,2,3,5 and others.. this is folders of posts images.. How I can write this folders on one folder posts?

Please sign in or create an account to participate in this conversation.