The text input field
To convert the input fields, a facade is used. The input field’s HTML is as follows:
<input type="email" class="form-control" name="email" value="{{ old('email') }}">
Converting the preceding input field using a façade looks like this:
{!! Form::input('email','email',old('email'),['class'=>'form-control' ]) !!}
Similarly, the text field becomes:
{!! Form::input('password','password',null,['class'=>'form-control']) !!}
The input fields have the same signature. Of course, this can be refactored as follows:
<?php $inputAttributes = ['class'=>'form-control'] ?> {!! Form::input('email','email',old('email'),$inputAttributes ) !!} ... {!! Form::input('password','password',null,$inputAttributes ) !!}
The label tag
The label
tags are as follows:
<label class="col-md-4 control-label">E-Mail Address</label> <label class="col-md-4 control-label">Password</label>
To convert the label
tags (E-Mail Address
and Password
), we will first create an array to hold the attributes, and then pass this array to the labels, as follows:
$labelAttributes = ['class'=>'col-md-4 control-label'];
Here is the form label code:
{!! Form::label('email', 'E-Mail Address', $labelAttributes) !!} {!! Form::label('password', 'Password', $labelAttributes) !!}
Checkbox
To convert the checkbox to a facade, we will convert this:
<input type="checkbox" name="remember"> Remember Me
The preceding code is converted to the following code:
{!! Form::checkbox('remember','') !!} Remember Me
Tip
Remember that the PHP parameters should be sent in single quotation marks if there are no variables or other special characters, such as line breaks, inside the string to parse, while the HTML produced will have double quotes.
Comments