How to insert data in laravel 8
How to insert data into database in laravel 8 using Eloquent model
In this tutorial, you will learn how to insert data in database using Eloquent model in laravel 8, so before getting started create a new laravel project and give the Database Connection in .env file.
Step 1: Create a Model and Migration by following command:
Model: Lets open Student Model in following path: app/Model/Student.php
Migration: Lets open create_students_table.php Migration table in following path: database/migrations/2021_05_30_create_students_table.php: (ADD this in your migration table)
Now lets migrate this students table into our database by following command:
Step 2: Go to web.php file in the following path as: routes/web.php and create a route (url) as follows:
Step 3: Create a Controller named StudentController by following command:
after successfully creating the controller lets write the code to View the FORM and insert data from Form in Laravel as follows:
Step 4: Create a blade file named create.blade.php in a student folder as show in following the path as: resource/views/student/create.blade.php
Note: I have used Bootstrap 5 verison to design the User Interface.
Step 6: Now we are done with the code of Insert data in laravel. Let's Run the artisan command to start the application as follows:
after servering the artisan - goto: http://localhost:8000/add-student
Latest PostsLaravel 8 Login and Registration System Tutorial | User Authentication How to delete data from database using Eloquent Modal How to edit and update data into database in php mysql How to fetch/retrieve data from database in Laravel 8 How to insert data in laravel 8 How to create a Controller and Resource Controller in Laravel 8 How to make Model and Migration in Laravel 8 How to install laravel 8
© Copyright - 2018 - 2021 | All rights reserved at Funda of Web IT