【问题标题】:Laravel Form Model Binding with File Upload is not working带有文件上传的 Laravel 表单模型绑定不起作用
【发布时间】:2016-03-10 04:16:55
【问题描述】:

我正在尝试在 laravel 5.2 中使用表单模型绑定上传文件。但它不起作用我没有在控制器中获取文件数据。

{!! Form::model($settings, ['route' => ['admin.settings.update', $settings->id], 'class' => 'form-horizontal', 'role' => 'form', 'method' => 'PATCH',  'fiels' => true  , 'id' => 'edit-settings']) !!}

<div class="form-group">

    {!!  Form::file('logo') !!}

</div>

{!! Form::close() !!}

在控制器中,我已正确导入输入外观并尝试获取这样的文件对象。

$image = Input::all('logo'); 
OR
$image = Input::file('logo');

但我得到的是文件名,而不是总文件对象。

【问题讨论】:

    标签: php laravel file-upload laravel-5.2


    【解决方案1】:

    像这样更新你的表单模型,你拼错了文件名

    {!!Form::model($settings, ['route' => ['admin.settings.update', $settings->id], 'class' => 'form-horizontal', 'role' => 'form', 'method' => 'PATCH',  'files' => true  , 'id' => 'edit-settings']) !!}
    

    然后在你的控制器中,这样做,

    Input::file('logo'); 而不是Input::all('logo'); 因为Input::all(); 返回所有表单输入。所以试试这个Input::file('logo');

    【讨论】:

      猜你喜欢
      • 2017-06-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-14
      • 1970-01-01
      • 2013-05-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多