An introduction to Eloquent ORM in Laravel
interview questions , PHP , Uncategorized / June 20, 2018

ORM refers to Object Relational Mapping.What ORM tools like  Eloquent does is that they are equipped with a metadata descriptor which helps in connecting object code to a relational database.To learn more on ORM refer this article. Now,we know that sequelize is an ORM tool that is used to connect node applications to relational databases such as Mysql/postgres.For PHP Developers ,Laravel is equipped with a very simple,efficient ORM called Eloquent ORM. Using Eloquent To create model class we use the following command

Now in case you dont know,Artisan is a command line interface provided with Laravel just like the other command line interfaces you might have used,like angular-cli,Artisan helps you to generate files while working with Laravel. The above command creates a model file for our Table and it looks like this

As you can see all models extend “Illuminate\Database\Eloquent\Model” Also note that the table has ‘snake case plural’ name of the class.That is ‘televisions’ table and ‘television’ class.Uncomment the $table variable in the above code to use custom table name. Now,To generate a migration script on creating the model.This can be done using the following command.

The migration file looks like this

To run the…

Share this page in social media platforms