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 laravel 8 using Eloquent model, so before getting started create a new laravel project and give the Database Connection in .env file.
Now, to insert data in laravel 8 into database using Eloquent model.
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 PostsHow to get/find data by multiple ids in laravel How to create or generate slug in laravel 8 How to show session flash message in laravel 8 How to show success message in laravel 8 Laravel 8 set custom messages in form request validation Laravel 8 Form Request Validation How to Create Pagination in Laravel 8 How to upload image in laravel 8 How to get data from database by id in laravel 8 Laravel 8 Login and Registration System Tutorial | User Authentication
© Copyright - 2018 - 2022 | All rights reserved at Funda of Web IT