Laravel Eloquent

Last Updated: August 4, 2021

Laravel Eloquent ORM is the Active Record implementation

Each database table has a corresponding model and you can use these models to query, insert, update and delete.

You can first create a model with artisian command and then create the corresponding table in database( We call this migrate)

How to create model

How to create table in database

Basic operations

count() to get number of rows returned

$products = Product::where('price', '<=', 10)->get();
$productCount = $products->count();

In the above example, first you get the collection and then run the count(). This method has the performance issue but you can use the following way to do the same

$productCount = Product::where('price', '<=', 10)->count();