Find the Best Cosmetic Hospitals

Explore trusted cosmetic hospitals and make a confident choice for your transformation.

“Invest in yourself — your confidence is always worth it.”

Explore Cosmetic Hospitals

Start your journey today — compare options in one place.

Inserting data in Database through Model.

There are many methods for inserting data in database through Model. See below:-

Migration is common in all methods in which we defined the table name and default value of all column’s. See below the migration code:-

Method 1: Through object.

We can insert data using Object in our controller. See the below code for help:-

Where, $project = Object.

See Output below:-

Method 2: Through Controller

We can insert data by using constructor in our controller. See the below code for help:-

But, whenever we are inserting data by using controller then we need to use fillable or guarded property in model otherwise it returns an error.

See below how to use fillable:-

protected $fillable = [“key1″,”key2”];

Note:- We add value of key in fillable which we want to add in the database.

See below how to use guarded:-

protected $guarded = [“key1″,”key2”];

Note:- We add the value of key in guarded which we don’t want to add in the database.

See the Output below:-

insertion by using fillable.

insertion by using guarded.

method 3: Through create() method

We can insert data using create() method in our controller. See the below code for help:-

As above property, it also depends on fillable and guarded.

See the output below:-

Find Trusted Cardiac Hospitals

Compare heart hospitals by city and services — all in one place.

Explore Hospitals
With MotoShare.in, you can book a bike instantly, enjoy doorstep delivery, and ride without worries. Perfect for travelers, professionals, and adventure enthusiasts looking for a seamless mobility solution.

Related Posts

What is Laravel and use cases of Laravel?

What is Laravel? Laravel is an open-source, free PHP web framework designed for the development of web applications following the model-view-controller (MVC) architectural pattern. It was generated…

Read More

Complete guide of Laravel certification courses, tutorials & training

What is Laravel Laravel is a reliable and simple to use open-source PHP framework. It adheres to the model-view-controller pattern of design. Laravel makes use of pre-existing…

Read More

Top 100 laravel interview questions and answers

1) What is Laravel? Laravel is an open-source widely used PHP framework. The platform was intended for the development of web application by using MVC architectural pattern….

Read More

[SOLVED] Laravel : Supervisor FATAL/BACKOFF Exited too quickly (process log may have details)

Problem I’m trying to use Laravel queues with a supervisor but the service is not working properly. When I try to check status:$ sudo supervisorctl status$ laravel-worker:laravel-worker_00:…

Read More

How to Login with Token in Laravel PHP Framework?

How to Login with Token in Laravel PHP Framework? Step 1. Create a new Project, so write down the following command on Git Bash: Step 2. Move…

Read More

Directory Structure Of Laravel Application

devopsschool – This is Project Folder app – The app directory contains the core code of your application. bootstrap – The bootstrap directory contains the app.php file…

Read More