繁体   English   中英

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() !!}

在Controller中,我已经正确导入了Input Facades,并尝试获取这样的文件对象。

$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');

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM