How to insert data in database using Laravel framework

Today, We want to share with you insert form data into database using laravel.In this post we will show you insert form data into database using laravel 6, hear for laravel insert data into table without model we will give you demo and example for implement.In this post, we will learn about insert query in laravel with an example.

laravel insert data into table using model

There are the Following The simple About insert data in laravel 7 Full Information With Example and source code.

As I will cover this Post with live Working example to develop laravel insert query mysql, so the laravel db::query is used for this example is following below.

how to insert data in database using laravel framework PHP.

For insert data in MySQL using laravel first i have to make a table in data base.

here The INSERT INTO statement is used to insert create fresh new data to a MySQL table in data base:

INSERT INTO statement

INSERT INTO table_name (column1, column2, column3,...)
VALUES (value1, value2, value3,...)

To learn more about SQL, please visit our SQL tutorial.

For creating table the SQL query is:

Step 1: SQL Query

CREATE TABLE member_details

CREATE TABLE member_details
profile_nm varchar(50),
real_nm varchar(50),
full_address varchar(50),
email varchar(50),

Create 3 files for insert data in Laravel :

  • MemberInsertController.php (app/Http/Controllers/MemberInsertController.php)
  • Member_create.php (resources/views/Member_create.php)
  • web.php (routes/web.php)

Step 2: View File


member Management | Add

@if (session('status'))


First Name
Last Name
City Name

Step 3: Controller File


			'full_address' => 'required|string|min:3|max:255',
			'email' => 'required|string|email|max:255'
		$validator = Validator::make($request->all(),$rules);
		if ($validator->fails()) {
			return redirect('insert')
            $data = $request->input();
				$member = new MemberInsert;
                $member->profile_nm = $data['profile_nm'];
                $member->real_nm = $data['real_nm'];
				$member->full_address = $data['full_address'];
				$member->email = $data['email'];
				return redirect('insert')->with('status',"Insert successfully");
			catch(Exception $e){
				return redirect('insert')->with('failed',"operation failed");

Step 4: Model File


Step 5: Routes File


How To Insert New Database Records in Laravel Eloquent?

To insert a new record into a database using Laravel's Eloquent ORM, you can follow these steps:

Create a new instance of the model you want to insert a record for.

$newRecord = new YourModel();

Set the values of the attributes for the new record.

$newRecord->attribute1 = 'value1';
$newRecord->attribute2 = 'value2';

Alternatively, you can pass an array of attribute values to the model's constructor:

$newRecord = new YourModel([
    'attribute1' => 'value1',
    'attribute2' => 'value2',

Call the save() method on the new record instance.


This will insert a new record into the database with the attribute values you have set.

Alternatively, you can use the create() method to create and save a new record in one step:

    'attribute1' => 'value1',
    'attribute2' => 'value2',

Note that when using the create() method, all the attributes in the model's $fillable property (or $guarded property if you want to specify which attributes are not mass-assignable) must be set in the array passed to create().


You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about insert form data into database using laravel.
I would like to have feedback on my blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Leave a Comment