How to create a text input field in Laravel

In this post, we are going to create a simple text input field with HTML and Form builder package. To create a text box use the following code.

See Also : Creating a Form Label Element in Laravel

{{ Form::text('username') }}

This will produce,

<input name="username" type="text">

To set a default value for the input field, pass second parameter.

{{ Form::text('username', 'Harshal') }}

The above code will generate following HTML output,

<input name="username" type="text" value="Harshal">

You can also add HTML attributes like ‘class’ or ‘id’ to this field by passing third parameter in form an associative array.

{{ Form::text('username', 'Harshal', array('class' => 'myClass')) }}

This will output,

<input class="myClass" name="username" type="text" value="Harshal">



Leave a Comment.