我在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 type="text" name="price" id="price" value="">
但仍然获得上述优先级,这可能吗?
你可以尝试使用它:
<input id="price" name="price" type="text" value="{{{ Form::getValueAttribute('price', null) }}}">
这是 Form::text 调用的用于替换值的函数。
拉拉维尔4 Form::getValueAttribute
功能:
/**
* 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);
}
}