Eloquent ORM

It is object relational mapper that provides smooth interaction with database.
 

Using global scope in eloquent

Like local scopes for repeating eloquent conditions we can use global scope also to all queries of a given model....


How to use eloquent when - more elegant way of using if statement

If dynamic query is being built using eloquent builder based on dynamic search queries such as user id or post...


Getting difference in days between created_at and updated_at using accessors in eloquent model

Accessors helps to change particular model values going through each of it if used in loop in view. Moreover, it...


Implementing one to many Polymorphic relationship

Suppose user has many photos and post also has many photos. Hence instead of making two separate tables like photo_users...


Implementing many to many Polymorphic relationship

Suppose, posts can have many photos then photos can relate to multiple posts also. Same goes for product table. That...


Using seeder and factory to create dummy data for pivot table

Suppose there are three tables communities, topics, posts and one pivot table community_topic ( in singular ). Hence if we...


Seeding additional fields and timestamps within pivot table

Step 01: create fresh laravel project composer create-project laravel/laravel advanced_pivot_table Step 02: Setting Up scaffolding migration of Role with artisan...


Using has many through relationship with users, roles and posts table

Suppose user has many posts and post belongs to user. Then role has many users and user belongs to role....


Querying records with relationship using author, book and rating table

Suppose there are three tables - authors, books and rating. In this post, we will see some example codes of...


Creating records with relationship using author and book in laravel

In this post we will be creating records using relationship. For the sake of simplicity we will seed data for...