Creating a New Model Based Form

Problem

You want the fields in your form to be bound with a model.

Solution

Open your form with Form::model().

Usually this is done in a blade template.

{{ Form::model($item, array('route' => array('items.update', $item->id))) }}

Use this instead of Form::open()

Now any Form::input(), Form::textarea() and Form::select() will use the model to populate the data.

Discussion

There's actually an order of precedence for populating your form. The precedence is FEM.

  1. (F)lash Data from the Session. This is where old input is stored from the previous request. This allows your form to be populated with previously entered data in case of errors.
  2. (E)xplicitly passed data. For instance, if you call Form::input() and specify the value argument, this will be used next.
  3. (M)odel Data. If the model has the same named attribute as the form field, its value will be used.
comments powered by Disqus