borrie's avatar

Nova: store image in different folder

Hello everyone,

I recently started with Nova. My users can upload an avatar om my website, and it will be stored at example.com/images/imagename.jpg.

In the Nova dashboard I want to be able to upload a different Image, but I can't seem to get Nova save the image into the right folder.

      return [
            Image::make('uri')
                ->store(function ($request) {
                    return [
                        'attachment' => $request->attachment->store('userimages'),
                    ];
                })
                ->disk('userimages')
                ->maxWidth(400)
                ->prunable()

        ];

The above code will give an error, saying "Call to a member function store() on null". So it seems the $request variable is null. However I don't know how to get this working, since I did this via the documentation.

0 likes
1 reply
borrie's avatar

I have been able to solve it.

I created a disk "user images" and pointed the root to public_path('images').

      'userimages' => [
            'driver' => 'local',
            'root' => public_path('images'),
            'url' => env('APP_URL').'/images',
            'visibility' => 'public',
        ],
1 like

Please or to participate in this conversation.