adminarchitect / core

AdminArchitect - Active Admin for Laravel
http://adminarchitect.com
MIT License
211 stars 66 forks source link

Laravel tries to acces file upload after laravel-stapler moved it #1

Closed eduardoarandah closed 7 years ago

eduardoarandah commented 7 years ago

When using laravel-stapler get an "FileNotFoundException" error on store methods.

This is not an error of laravel-stapler, because problem happens AFTER model is saved.

Problem is this: /vendor/adminarchitect/core/src/Controllers/AdminController.php @ redirectTo creates a second instance of the request, that validates the file, but the file doesn't exist, laravel-stapler alredy moved it

This is the error:


FileNotFoundException

 The file "C:\wamp\tmp\php9259.tmp" does not exist
--
in File.php (line 37)
at File->__construct('C:\\wamp\\tmp\\php9259.tmp', true)in UploadedFile.php (line 96)
at UploadedFile->__construct('C:\\wamp\\tmp\\php9259.tmp', 'agent-02.jpg', 'image/jpeg', 78436, 0, false)in UploadedFile.php (line 105)
at UploadedFile::createFromBase(object(UploadedFile))in InteractsWithInput.php (line 251)
at Request->Illuminate\Http\Concerns\{closure}(object(UploadedFile))
at array_map(object(Closure), array('avatar' => object(UploadedFile)))in InteractsWithInput.php (line 252)
at Request->convertUploadedFiles(array('avatar' => object(UploadedFile)))in InteractsWithInput.php (line 233)
at Request->allFiles()in InteractsWithInput.php (line 121)
at Request->all()in InteractsWithInput.php (line 71)
at Request->exists('save')in Facade.php (line 221)
at Facade::__callStatic('exists', array('save'))in AdminController.php (line 66)
at Request::exists('save')in AdminController.php (line 66)
at AdminController->redirectTo('test', 19)in ScaffoldController.php (line 126)
at ScaffoldController->store('test', object(UpdateRequest))

this happens:

ScaffoldController @ store instantiates UpdateRequest $request and laravel-stapler moves the file in line 120

then calls AdminController @ redirectTo where it instantiantes another request in Request::exists('save');

Laravel executes this method, failing: Request->convertUploadedFiles

This solved it in my machine: ScaffoldController @ store

passing the request as variable

return $this->redirectTo($page, $eloquent->id, $request)->with(
            'messages',
            [trans('administrator::messages.create_success')]
        );

then using the same request object in AdminController@redirectTo


    protected function redirectTo($module, $key = null, $request)
    {
        if ($next = $request->get('back_to')) {
            return redirect()->to($next);
        }

        if ($request->exists('save')) {
            return redirect(route('scaffold.edit', $this->toMagnetParams(['module' => $module, 'id' => $key])));
        }

        if ($request->exists('save_return')) {
            if ($previous = $this->getPreviousUrl()) {
                $this->forgetPreviousUrl();

                return redirect()->to($previous);
            }

            return redirect(route('scaffold.index', $this->toMagnetParams(['module' => $module])));
        }

        return redirect(route('scaffold.create', $this->toMagnetParams(['module' => $module])));
    }

I don't know if this is the best approach, didn't make any more tests.

reproduce the error with this simple test: https://bitbucket.org/eduardoarandah/admin-architect-test