Creating a Form Input Field

Problem

You want to create a form input field.

Instead of writing HTML directory you want to use Laravel's Form facade.

Solution

Use the Form::input() method.

The method takes 4 arguments.

  1. $type - (required) The first argument specifies the type of input. Values such as "text", "password", "file", etc. are accepted.
  2. $name - (required) The second argument is name.
  3. $value - (optional) The third argument is the value for the input field.
  4. $options - (optional) The fourth argument is an array of additional field attributes. The array can be populated with items having keys such as "id", "size", or "class".

Usually, this is used in a Blade template.

{{ Form::input('text', 'name') }}
{{ Form::input('email', 'email_address', null, ['class' => 'emailfld']) }}

Discussion

Use the specific method for the type of field you want.

Instead of calling Form::input() directly, use one of the following:

Model binding

See the Creating a New Model Based Form recipe for details on how the input value is overridden if you bind a model to the form.

comments powered by Disqus