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.
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.
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' => [
...
Collective\Html\HtmlServiceProvider::class,
...
],
'aliases' => [
...
'Form' => Collective\Html\FormFacade::class,
'Html' => Collective\Html\HtmlFacade::class,
...
],
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 GET
, PUT
and DELETE
methods.
Now, we will how to use the route in form and how to use the controller with its method in form.
Form::open(['route' => 'route.name'])
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]])
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.
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');
or
Form::checkbox('name', 'value', true);
// Input type Radio Button
Form::radio('name', 'value');
or
Form::radio('name', 'value', true);
// Input type Number
Form::number('name', 'value');
// Input type Date
Form::date('name', \Carbon\Carbon::now());
// Input type File
Form::file('image');
// Input type Dropdown
Form::select('size', ['L' => 'Large', 'S' => 'Small']);
or
Form::select('size', ['L' => 'Large', 'S' => 'Small'], 'S');
// Input type Submit
Form::submit('Submit!');
You might also like:
In this tutorial, I am giving information about laravel artisan command which can help you to clear your application'...
May-18-2020
In this article, we will see laravel 10 create an ajax pagination example. Here, we will learn about how to create...
Apr-17-2023
Digital marketing is the component of marketing that utilizes internet and online bas...
Oct-19-2021
In this article, we will explore the process of sending emails in Laravel, covering versions 6, 7, 8, 9, and 10. Email f...
Sep-02-2020