laravel form | Laravel - Forms
What is Laravel Form?
- In a database context, a form is a window or screen that contains numerous fields, or spaces to enter data.
- Each field holds a field label so that any user who views the form gets an idea of its contents.
- A form is more user friendly than generating queries to create tables and insert data into fields.
- Laravel provides various in-built tags to handle HTML forms easily and securely. All the major elements of HTML are generated using Laravel.
- To support this, we need to add HTML package to Laravel using composer.
laravel , laravel framework , laravel documentation , laravel tutorial , laravel install , laracasts
Example 1
Step 1
- Execute the following command to proceed with the same.
Step 2
- This will add HTML package to Laravel as shown in the following image.
Step 3
- Now, we need to add this package to Laravel configuration file which is stored at config/app.php. Open this file and you will see a list of Laravel service providers as shown in the following image. Add HTML service provider as indicated in the outlined box in the following image.
Step 4
- Add aliases in the same file for HTML and Form. Notice the two lines indicated in the outlined box in the following image and add those two lines.
Step 5
- Now everything is setup. Let’s see how we can use various HTML elements using Laravel tags.
Opening a Form
laravel , laravel framework , laravel documentation , laravel tutorial , laravel install , laracasts
Generating a Label Element
Generating a Text Input
laravel , laravel framework , laravel documentation , laravel tutorial , laravel install , laracasts
Specifying a Default Value
Generating a Password Input
laravel , laravel framework , laravel documentation , laravel tutorial , laravel install , laracasts
Generating a File Input
Generating a Checkbox Or Radio Input
laravel , laravel framework , laravel documentation , laravel tutorial , laravel install , laracasts
Generating a Checkbox Or Radio Input That Is Checked
Generating a Drop-Down List
Generating A Submit Button
Example 2
Step 1
- Copy the following code to create a view called resources/views/form.php.
resources/views/form.php
Step 2
- Add the following line in app/Http/routes.php to add a route for view form.php
app/Http/routes.php
Step 3
- Visit the following URL to see the form.
- http://localhost:8000/form
Step 4
- The output will appear as shown in the following image.