Search code examples
laravellaravel-5laravel-5.3

Laravel: variable as form value


First Laravel Project.

I want to make an "edit screen" where the "old values" are the predefined default value of the form input field.

I tried this:{{ Form::text('brand', '$product[0]->brand') }} But I got back

$product[0]->brand

Instead of

Test brand

What I did wrong? What's the good syntax?


Solution

  • Usually, Laravel should reuse the last entry the user used if the form isn't validated as you can read here :

    Also, please note that the value will first come from Flash Session Input, only secondly will the value argument be used. This means if your previous request was this form it will automatically display the value the user last entered.

    But, if you want, can't you use something like

    {{ Form::text('brand', $product[0]->brand) }}
    

    Because you were saying you wanted that specific string by putting ' around your variable.