0

I'm having trouble retrieving any file data from my form post. I'm using the Laravel form Macros but I've also tried plain HTML inputs.

When I post the form there's no file input being posted, I've also tried dumping the post data in my controller just to double check. Not sure where I'm going wrong here...

Here's a quick rundown of the code:

{{ Form::open(array(
    "url"   => $formAction,
    "files" => true,
    "id"    => "settings-form",
    "class" => "form-horizontal"
)) }}

    {{ Form::file($name, array(
        "class" => "input-sm"
    )) }}

{{ Form::close() }}
Shane Da Silva
  • 469
  • 1
  • 6
  • 15
  • 1
    Have you tried using `Input::file()`? As explained here: http://laravel.com/docs/requests#files – Aken Roberts Aug 08 '14 at 17:33
  • I have. There's no data even being posted is the problem though. It's almost as if the post data is being removed. – Shane Da Silva Aug 08 '14 at 17:44
  • Use your browser's inspector to check the requests being made. There may be a redirect or something happening in between that you aren't noticing. – Aken Roberts Aug 08 '14 at 19:03

2 Answers2

0

Instead of using the url attribute, try specifying a route:

{{ Form::open(['route' => 'myRoute.store', 'files' => true, 'class' => 'form form-horizontal']) }}

Or if you are updating an existing record:

{{ Form::open(['route' => ['myRoute.update', $modelId], 'files' => true, 'class' => 'form form-horizontal']) }}

Or if you want to use model-binding:

{{ Form::model($myModel, ['route' => ['myRoute.update', $model->id], 'files' => true, 'class' => 'form form-horizontal']) }}

That usually works for me, never had issues uploading this way.

mike.bronner
  • 1,203
  • 1
  • 20
  • 39
  • Thanks but don't think this is the issue. The form posts properly, it's only file data that isn't showing up... any other input type posts to the controller just fine. – Shane Da Silva Aug 11 '14 at 20:16
0

Figured it out... I was serializing my form data and submitting it via jQuery's AJAX function.

Better answer here if interested: https://stackoverflow.com/a/4545089/597546

Community
  • 1
  • 1
Shane Da Silva
  • 469
  • 1
  • 6
  • 15