Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/266.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Laravel表单模型绑定和html输入字段_Php_Laravel_Blade - Fatal编程技术网

Php Laravel表单模型绑定和html输入字段

Php Laravel表单模型绑定和html输入字段,php,laravel,blade,Php,Laravel,Blade,我在Laravel中为我的更新视图使用表单模型绑定,以实现优先级 1.会话闪存数据(旧输入) 2.显式传递值 3.模型属性数据 {{ Form::model($model, array('url' => $route.'/update/'.$model->id)) }} {{ Form::label('price', trans_choice('app.price', 1), array('id' => 'price_label')) }} {{ Form::text('pri

我在Laravel中为我的更新视图使用表单模型绑定,以实现优先级 1.会话闪存数据(旧输入) 2.显式传递值 3.模型属性数据

{{ Form::model($model, array('url' => $route.'/update/'.$model->id)) }}
{{ Form::label('price', trans_choice('app.price', 1), array('id' => 'price_label')) }}
{{ Form::text('price', null, array('id' => 'price')) }}
这可以很好地工作,但我想做同样的事情,而不使用刀片符号的输入场,也就是说,我想取代

{{ Form::text('price', null, array('id' => 'price')) }} 



但是仍然可以获得上述优先级,这可能吗?

您可以尝试使用以下选项:

<input id="price" name="price" type="text" value="{{{ Form::getValueAttribute('price', null) }}}">

谢谢你的建议,但这实际上会覆盖模型的默认值它不会覆盖模型的默认值。。。它实际上是模型用来设置值的函数。
<input id="price" name="price" type="text" value="{{{ Form::getValueAttribute('price', null) }}}">
/**
 * Get the value that should be assigned to the field.
 *
 * @param  string  $name
 * @param  string  $value
 * @return string
 */
public function getValueAttribute($name, $value = null)
{
    if (is_null($name)) return $value;

    if ( ! is_null($this->old($name)))
    {
        return $this->old($name);
    }

    if ( ! is_null($value)) return $value;

    if (isset($this->model))
    {
        return $this->getModelValueAttribute($name);
    }
}