使用文件上载的Laravel表单模型绑定不起作用

时间:2016-03-10 04:16:55

标签: php laravel file-upload laravel-5.2

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

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

1 个答案:

答案 0 :(得分:1)

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

    public async Task SetPlayerList()
    {
        //returns list of players and stores it to be sorted 
        _Players = await _ItemHandler.GetPlayerList();
        _PlayerList = new List<PriceCheckPlayerList>();

         //This is as much as I am able to get with my knowledge (I'm lacking)
        _Players = _Players.OrderBy()

        foreach (Player eap in _Players)
        {
            _PlayerList.Add(new PriceCheckPlayerList()
            {
                _Player = eap,
                SetYet = false,
                LastUpdated = DateTime.UtcNow, 
            });
        }
    }

然后在你的控制器中,执行此操作,

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