Form
Create Form Tag in Laravel

To Create HTML form by Laravel Form tags. There are some step.

1- Edit composer.json file that is available in root folder

"require": {
"laravelcollective/html": "5.6.*"
}

Then update compose by command prompt by composer update Command

2- Edit config/app.php. For update providers and aliases

'providers' => [
// ...
Collective\Html\HtmlServiceProvider::class,
// ...
],

Then add two class aliases

'aliases' => [
// ...
'Form' => Collective\Html\FormFacade::class,
'Html' => Collective\Html\HtmlFacade::class,
// ...
],

Create Form

{!! Form::open(['url' => 'submitform']) !!}
Test Form
{!! Form::close() !!}

Output
<form method="POST" action="http://localhost/shishir2/public/submitform" accept-charset="UTF-8"><input name="_token" type="hidden" value="Q1Z1XKS0tfFGbBYOVNwKX74iO2XAmLhrATb4Ij5R">
Test Form
</form>

Some Use full Form Control

{!! Form::token() !!}
To create CSRF Protection hidden field

{!! Form::label('email', 'E-Mail Address'); !!}
To create Email Label

{!! Form::text('username'); !!}
To enter text

{!! Form::password('password', ['class' => 'awesome']); !!}
To enter password

{!! Form::checkbox('name', 'value'); !!}
To check checkbox

{!! Form::radio('name', 'value'); !!}
To select radio button

{!! Form::date('name', CarbonCarbon::now()); !!}
To accept user date by calendar

{!! Form::number('name', 'value'); !!}
To enter date only

{!! Form::file('image'); !!}
To select file

{!! Form::select('size', ['' => 'Select File', '1' => 'Delhi', '2' => 'Mumbai']); !!}
To create Dropdown list

{!! Form::submit('Submit') !!}

To Create Complete Form

<html>
<head></head>
<body>
{!! Form::open(['url' => 'submitform']) !!}
<table>
<tr>
<td>Name</td>
<td>{!! Form::text('username'); !!}</td>
</tr>
<tr>
<td>Email</td>
<td>{!! Form::text('email'); !!}</td>
</tr>
<tr>
<td>Gender</td>
<td>{!! Form::radio('gender', 'male'); !!}Male{!! Form::radio('gender', 'female'); !!}Female</td>
</tr>
<tr>
<td>City</td>
<td>{!! Form::select('city', ['' => 'Select City', '1' => 'Delhi', '2' => 'Mumbai']); !!}</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>{!! Form::submit('Submit') !!}</td>
</tr>
</table>
{!! Form::close() !!}
</body>
</html>

Routes

<?php
Route::get('/myform','Usercontroller@index');

Controller

<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;

class Usercontroller extends Controller
{
//
public function index(){
return view('myform');
}
}


Previous
Next