Laravel 9 Form Collective Example

Websolutionstuff | Jan-20-2023 | Categories : Laravel

In this article, we will see laravel 9 form collective example. Here, we will learn how to use collective form and how to install form in laravel 8 and laravel 9. Sometimes you got an error like class "form" not found in laravel 7, laravel 8, and laravel 9. So, we will solve class not found in laravel 9.

So, let's see the laravel 9 form example, laravelcollective/html, class form not found in laravel 9, class form not found in laravel 9, and how to install form collective in laravel 9.

laravel 9 Form


laravelcollective/html is provided an HTML textbox, radio button, select box, checkbox, and many more with laravel. They provide different methods to use those input fields we need to add this facade class 'collective\html\formfacade' if not added.


Install Laravel Collective Form

In this step, we will install the laravel collective form using the composer command.

$ composer require laravelcollective/html

Note: If you are using the older version of laravel then you need to add the below code in the app.php file.

'providers' => [
'aliases' => [
      'Form' => Collective\Html\FormFacade::class,
      'Html' => Collective\Html\HtmlFacade::class,



Use of Form

Now, we will see how to use the laravel collective form and different input types.

Opening A Form

{!! Form::open(['url' => 'form/example']) !!}
{!! Form::close() !!}

By default, a POST method will be assumed. But, you are free to specify any other method like the below code.

Form::open(['url' => 'foo/bar', 'method' => 'put'])

Note: HTML forms only support POST and GETPUT and DELETE methods.


Use Route and Controller in Form

Now, we will how to use the route in form and how to use the controller with its method in form.

Form::open(['route' => ''])

Form::open(['action' => 'UserController@index'])

You can pass parameters in the form like the below code.

Form::open(['route' => ['user.edit', $user->id]])

Form::open(['action' => ['UserController@edit', $user->id]])


Use Label with HTML Attribute

Now, we will see the form label with HTML attributes like palace holder and class name.

Form::label('First Name', 'Enter First Name', ['class' => 'awesome']);

Form::label('Last Name', 'Enter Last Name', ['class' => 'awesome']);

Note: After creating a label, any form element you create with a name matching the label name will automatically receive an ID matching the label name as well.


Use HTML Input Type

Laravel collective form provides HTML input types like text, email, password, file, checkbox, radio button,s and much more.

// Input type Text
Form::text('email', '[email protected]');

// Input type Password
Form::password('password', ['class' => 'awesome']);

// Input type Checkbox
Form::checkbox('name', 'value'); 
Form::checkbox('name', 'value', true);

// Input type Radio Button 
Form::radio('name', 'value');
Form::radio('name', 'value', true);

// Input type Number
Form::number('name', 'value');

// Input type Date
Form::date('name', \Carbon\Carbon::now());

// Input type File

// Input type Dropdown
Form::select('size', ['L' => 'Large', 'S' => 'Small']);
Form::select('size', ['L' => 'Large', 'S' => 'Small'], 'S');

// Input type Submit


You might also like:

Recommended Post
Featured Post
Laravel 8 Custom Email Verification Tutorial
Laravel 8 Custom Email Verific...

In this article, we will see an example of laravel 8 custom email verification. Many web applications require users...

Read More


Laravel 9 User Roles and Permissions Without Package
Laravel 9 User Roles and Permi...

In this article, we will see laravel 9 user roles and permissions without package. Roles and permissions are an imp...

Read More


Special Characters Not Allowed Validation In Laravel 9
Special Characters Not Allowed...

In this article, we will see special characters not allowed validation in laravel 9. Here, we will learn special ch...

Read More


How To Import SQL File Into MySQL Using Command
How To Import SQL File Into My...

In this article, we will see how to import SQL files into MySQL using the command. You can import databases in multiple...

Read More