0

I am using Form Model Binding in Laravel for my update views in order to achieve the priority 1. Session Flash Data (Old Input) 2. Explicitly Passed Value 3. Model Attribute Data

{{ 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')) }}

This works fine but I would like to do the same without using the blade notation for input fiels, that is I would like to replace

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

with

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

but still get the above-mentioned priority, is this possible?

1 Answer 1

2

You can try to use this:

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

This is the function called by Form::text to replace the value.

Laravel 4 Form::getValueAttribute function:

/**
 * 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);
    }
}
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for your suggestion but this will actually overwrite the model's default value
It will not overwrite the model's default value... it is actually the function used by the model to set a value.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.