mardi 3 mars 2015

Reuse laravel form partial

When reusing a form partial with a Form::model() and Form::open() I'm running into problems on how to use default values.


For example when using the following form partial partials/form.blade.php:



{!! Form::text('myfield', 'Default') !!}
{!! Form::text('otherfield', '123') !!}
{!! Form::text('yetanother', 'Yet another default') !!}
// Etc


I would include it as follows, create.blade.php:



{!! Form::open() !!}
@include('partials/form.blade.php')
{!! Form::close() !!}


and for editing edit.blade.php:



{!! Form::model($mymodel) !!}
@include('partials/form.blade.php')
{!! Form::close() !!}


However the default values can't be used as then with the edit.blade.php all the model values are ignored (it will always be 'Default', '123' and 'Yet another default', and never the actual model values).


And when using null as the default value it would fill the model values for the edit.blade.php, but then the create.blade.php fields will be empty.


What would be a good way to use the model values in the edit and the "default" values for the new model?


Aucun commentaire:

Enregistrer un commentaire