Laravel表单模型绑定与文件上传不起作用


Laravel Form Model Binding with File Upload is not working

我正在尝试在 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');

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

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

{!!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');