簡體   English   中英

Laravel表單模型綁定和html輸入字段

[英]Laravel form model binding and html input fields

我在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="">

但仍然得到上述優先權,這可能嗎?

您可以嘗試使用此:

<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);
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM