douxing6532 2017-04-26 05:18
浏览 44

Laravel表单模型绑定编辑数组值

Create form works fine with the following code:

<div class="span3">
              {!! Form::input('text', 'tactic[]', null, array('id' => 'tactic', 'class' => ' form-control TabOnEnter', 'placeholder' => 'Tactics_1')) !!}
          </div>
<div class="span3">
              {!! Form::input('text', 'tactic[]', null, array('id' => 'tactic', 'class' => ' form-control TabOnEnter', 'placeholder' => 'Tactics_1')) !!}
          </div>
<div class="span3">
              {!! Form::input('text', 'tactic[]', null, array('id' => 'tactic', 'class' => ' form-control TabOnEnter', 'placeholder' => 'Tactics_1')) !!}
          </div>

This will store data in db like this: ["ui","iu","jh"]

So while editing this form shows error:

htmlentities() expects parameter 1 to be string, array given (View: C:\xampp\htdocs\projectesources\views\dashboard\Test\edit.blade.php)

I know this is because its not properly outputs array. FYI: in my model im using this

protected $casts = [
    'tactic' => 'array',
    ];

Any way in showing the values from db in edit form.

  • 写回答

0条回答 默认 最新

    报告相同问题?