jandante's avatar

Passing an UploadedFile to a new view

Hi,

I'm building a little website where the user is able to upload pictures. After the upload I do a check for the image size and if not a certain size I want to redirect to a view with jQuery Cropper. The uploaded picture should then be the source of the cropper canvas.

 if($validator->fails())
 {
   $photo = $request->file('photo');
   return redirect()->route('cropper', array('photo' => $photo));
  }

In my routes I then have the following:

   Route::get('cropper', ['as' => 'cropper', 'uses' => 'CropperController@index']);

And in my Controller I do a die and dump of the picture as follows:

  public function index(UploadedFile $photo)
  {
     dd($photo);
  }

Now if I leave the UploadedFile $photo part away in the controller I get no error. So i suppose the routing is OK. But with the variable passing I get the following error:

BindingResolutionException in Container.php line 823: Unresolvable dependency resolving [Parameter #0 [ $path ]] in class Symfony\Component\HttpFoundation\File\UploadedFile

I don't really get the error. I've also tried to change the route to a post route, but that would give me a MethodNotAllowedException since I'm not sending from a form...

Thanks for your feedback/input!

0 likes
2 replies
Bloomanity's avatar
Level 22

Instead of redirecting to a route, render a view with that photo

2 likes

Please or to participate in this conversation.