From static HTML to static methods

This login page begins with the following:

@extends('app')

It obviously uses the object-oriented paradigm to state that the app.blade.php template will be rendered. The following line overrides the content:

@section('content')

For this exercise, the form builder will be used instead of the static HTML.

The form tag

We will convert a static form tag to a FormBuilder method. The HTML is as follows:

<form class="form-horizontal" role="form" method="POST" action="/auth/login">

The method facade that we will use is as follows:

Form::open();

In the FormBuilder.php class, the $reserved attribute is defined as follows:

protected $reserved = ['method', 'url', 'route', 'action', 'files'];

The attributes that we need to pass to an array to the open() method are class, role, method, and action. Since method and action are reserved words, it is necessary to pass the parameters in the following manner:

Laravel form facade method array elementHTML Form tag attribute
methodmethod
urlaction
rolerole
classclass

Thus, the method call looks like this:

{!! 
  Form::open(['class'=>'form-horizontal',
  'role =>'form',
  'method'=>'POST',
  'url'=>'/auth/login']) 
!!}

The {!! !!} tags are used to start and end parsing of the form builder methods. The form method, POST, is placed first in the list of attributes in the HTML form tag.

Tip

The action attribute actually needs to be a url. If the action parameter is used, then it refers to the controller action. In this case, the url parameter produces the action attribute of the form tag.

Other attributes will be passed to the array and added to the list of attributes. The resultant HTML will be produced as follows:

<form method="POST" action="http://laravel.example/auth/login" accept-charset="UTF-8" class="form-horizontal" role="form">

<input name="_token" type="hidden" value="wUY2hFSEWCzKHFfhywHvFbq9TXymUDiRUFreJD4h">

The CRSF token is automatically added, as the form method is POST.