vanilophp / demo

Vanilo Demo Application
https://vanilo.io/docs/
190 stars 54 forks source link

Uploading no selected picture on product edit page generates exception #14

Closed j-dohnalek closed 5 years ago

j-dohnalek commented 5 years ago

When editing product in dashboard and I do not select any picture and press upload exception Spatie\MediaLibrary\Exceptions\FileCannotBeAdded\RequestDoesNotHaveFile appears. With message "The current request does not have a file in a key named images"

I am still using the demo from 2 weeks time, if it was fixed please close the issue.

j-dohnalek commented 5 years ago

Do not know if this helps https://github.com/spatie/laravel-medialibrary/issues/646

fulopattila122 commented 5 years ago

Vanilo v0.4 was released yesterday. Please use a fresh new install and check if that works. We've been testing it excessively in the last few weeks and haven't had this error, so it should work.

j-dohnalek commented 5 years ago

I have installed the version 0.4 and there are two problems. First when creating new product and attempting to upload a picture there is no button to submit the picture and the picture is not uploaded with the creation of the product.

Create form - No Submit image Edit form - Submit image

Second problem is the one I have highlighted yesterday. When I am on product edit page and just click the green submit button to upload a picture it will throw exception.

fulopattila122 commented 5 years ago

Hmm ok.., thanks for the report, I'll look into it shortly.

j-dohnalek commented 5 years ago

I am just having a look around the 0.4 now and the upload of files when creating products works. It it just the edit exception.

fulopattila122 commented 5 years ago

Do you mean that the only problem is when you submit Images on product edit form without files selected with the green arrow?

j-dohnalek commented 5 years ago

Yes

j-dohnalek commented 5 years ago

I have changed Vanilo\Framework\Http\Controllers\MediaController@store to

public function store(Request $request)
{
        if(!$request->has('images')){
            flash()->error(__('No image supplied, image is required!'));
            return redirect()->back();
        }

        // Laravel Black Magic
        $model = app(concord()->short($request->get('forType')))->find($request->get('forId'));

        $model->addMultipleMediaFromRequest(['images'])->each(function ($fileAdder) {
            $fileAdder->toMediaCollection();
        });

        flash()->success(__('Images have been added successfully!'));
        return redirect()->back();
}

and the exception is not triggered

fulopattila122 commented 5 years ago

Ok, I'll add that validation to the framework

fulopattila122 commented 5 years ago

It's been released in framework v0.4.1. To get the update run: composer update vanilo/framework

Thanks again for the report + the suggestion.