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

时间:2013-09-13 05:59:28

标签: php laravel blade

我在Laravel中使用Form Model Binding来获取更新视图以获得优先级 1.会话Flash数据(旧输入) 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')) }}

这样可以正常工作,但我想在不使用刀片表示法输入fiels的情况下做同样的事情,这就是我想要替换

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

<input type="text" name="price" id="price" value="">

但仍然得到上述优先权,这可能吗?

1 个答案:

答案 0 :(得分:2)

你可以尝试使用它:

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

这是Form :: text调用的函数,用于替换值。

Laravel 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);
    }
}
相关问题