简体   繁体   English

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

[英]Laravel Form Model Binding with File Upload is not working

I'm trying to upload file with form model binding in laravel 5.2. 我正在尝试在laravel 5.2中上传具有表单模型绑定的文件。 But it is not working I'm not getting file data in controller. 但它不起作用,我没有在控制器中获取文件数据。

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

In Controller I've properly imported Input Facades and trying to get file object like this. 在Controller中,我已经正确导入了Input Facades,并尝试获取这样的文件对象。

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

But I'm getting name of the file and not total file object. 但是我得到的是文件名而不是总文件对象。

update your form model like with this, you misspelled the file name 像这样更新您的表单模型,您拼写了错误的文件名

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

then in your controller, do this, 然后在您的控制器中执行此操作

Input::file('logo'); Instead Input::all('logo'); 而是Input::all('logo'); because Input::all(); 因为Input::all(); return all form inputs. 返回所有表单输入。 so try this one Input::file('logo'); 所以试试这个Input::file('logo');

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

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