Array to string conversion - Form Model Binding in Blade Templating Engine

时间:2016-09-01 06:22:32

标签: php laravel layout yield laravel-blade

Trying to update the fields using Form Model Binding, but I am stuck as the following error got displayed:

ErrorException in HtmlBuilder.php line 431: Array to string conversion (View: C:\xampp\htdocs\cms\resources\views\posts\edit.blade.php)

Edit.blade.php

{!! Form::model($post, ['method'=>'PUT', ['action'=>'PostsController@update', $post->id]]) !!}

        {{ csrf_field() }}
        {!! Form::label('title', 'Title: ') !!}
        {!! Form::text('title', null) !!}
        {!! Form::submit('Update Post') !!}

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

Htmlbuilder.php [Line 430-432]

if (! is_null($value)) {
            return $key . '="' . e($value) . '"';
        }

I have tried numerous solutions but got no success. I don't know where the problem is.

2 个答案:

答案 0 :(得分:2)

尝试将代码作为关联数组发送的代码:['method' => value, 'action' => value]但不是混合['method' => value, ['action' => value]]

{!! Form::model($post, ['method'=>'POST', 'action'=>['PostsController@update', $post->id]]) !!}

答案 1 :(得分:1)

You are missing some brackets. The value of action should be an array.

Try the following (write in a single line):

{!! Form::model($post,
    ['method'=>'PUT', 'action'=>
        [ 'PostsController@update', $post->id]
    ])
!!}