Eloquent and Model in Laravel

Here we will discuss about the eloquent ORM and insertion of data to database table via Model.

Eloquent model included with Laravel provides a simple, active record implementation for working with database. Each database table has a corresponding “model” which is used to interact with the table.

Model allows us to query for data in our tables and also insert new records into the table.

First of all we need to create a model and to create a model we can run the command given below:

php artisan make:model Product -a

This command will create a model , controller , migration and factory.

Once the model is created we can find the model under apps as shown in the image below:

Now moving forward we can insert details under the migration folder and migrate it in the database:

To migrate the data we know we need to execute php artisan migrate command and a table will be created in the database:

Now to insert data in the database we need to provide it in the controller:

After executing the command we can run the server and see the output in our browser and we can see the name in the page and also the details will be saved in the database.

You can see the video given below for more information:

Joydeep M
Latest posts by Joydeep M (see all)
Tagged :
0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x