Php Laravel表单模型绑定和html输入字段
我在Laravel中为我的更新视图使用表单模型绑定,以实现优先级 1.会话闪存数据(旧输入) 2.显式传递值 3.模型属性数据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
{{ 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);
}
}