Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

dd($request->all()); gives back empty array

Tags:

I am trying to upload a photo from my Laravel 5 app to be stored in AWS. I am using the Postman REST client to test. When I upload a photo, the request returns an empty array. Does anyone know why this might be? Here's the code for my Avatar Controller:

class AvatarController extends Controller {    public function __construct(AWS $aws)   {       $this->aws = $aws;   }  /**  * Store a new avatar for a user.  * POST northstar.com/users/{id}/avatar  */   public function store(User $user, Request $request)   {     dd($request->all());     // dd($request->file('photo'));      $file = $request->file('photo');     // $file = Request::file('photo');     // $file = Input::file('photo');      $v = Validator::make(       $request->all(),       ['photo' => 'required|image|mimes:jpeg,jpg|max:8000']     );      if($v->fails())       return Response::json(['error' => $v->errors()]);               $filename = $this->aws->storeImage('avatars', $file);      // Save filename to User model     $user->avatar = $filename;     $user->save();      // Respond to user with success     return response()->json('Photo uploaded!', 200);   } } 
like image 580
chloealee Avatar asked May 19 '15 19:05

chloealee


2 Answers

Found the answer - looks like there was an issue with my headers in Postman. I had both Accept application/json and Content-Type application/json. Once I removed Content-Type, all is fixed. Thanks!

like image 68
chloealee Avatar answered Sep 24 '22 09:09

chloealee


Bit late to the party, but might be usefull for others: My problem was that the Content-Type header value was application/json while the actual payload was form data. Changing the header to application/x-www-form-urlencoded fixed the issue.

like image 24
user3601546 Avatar answered Sep 22 '22 09:09

user3601546