Eloquent: Counting Records Based on a Condition (6 Techniques)
Updated: Jan 17, 2024
Introduction When using Laravel’s Eloquent ORM, one often encounters scenarios where it’s required to count records in a database table based on specific conditions. This allows developers to easily gather insights about......
How to Restore Soft Deleted Models in Eloquent
Updated: Jan 17, 2024
Introduction Eloquent, the ORM (Object-Relational Mapper) included with Laravel, provides the rich functionality of handling interactions with database tables effortlessly. One powerful feature is ‘Soft Deletes’, allowing......
How to Compare Two Models in Eloquent
Updated: Jan 17, 2024
Introduction When dealing with object-relational mapping in Laravel’s Eloquent, it is often necessary to compare two models to determine if they represent the same record in the database or to see what attributes have changed......
How to create REST API with Laravel (no views)
Updated: Jan 17, 2024
Introduction RESTful APIs are the backbone of modern web applications, providing a way for various systems to communicate with each other. Laravel, a powerful PHP framework, makes building these APIs a breeze, emphasizing simplicity,......
How to implement GraphQL in Laravel
Updated: Jan 17, 2024
Overview Integrating GraphQL into your Laravel project can be a game-changer for your web application. GraphQL provides a more efficient and powerful alternative to the traditional REST API. It allows clients to query for exactly the......
Laravel Eloquent: CRUD Example
Updated: Jan 17, 2024
Introduction Welcome to this Laravel Eloquent CRUD example tutorial. In this guide, we’ll dive deep into how to use Eloquent, Laravel’s own ORM (Object-Relational Mapper), to interact with your database using a rich and......
Laravel Eloquent: Return a fallback/default value if record not found
Updated: Jan 17, 2024
Introduction Laravel’s Eloquent ORM provides an elegant and easy-to-understand interface to interact with the database. Lifestyle of a developer using Laravel can be quite smooth until they encounter missing record errors. In......
Can you use Eloquent ORM without Laravel?
Updated: Jan 17, 2024
Introduction Eloquent ORM is a powerful Object-Relational Mapper designed for Laravel, but what if you want to use it without the full Laravel framework? Luckily, Eloquent can be implemented as a standalone package. In this tutorial,......
Using ‘UNION’ in Laravel Eloquent
Updated: Jan 17, 2024
Introduction The UNION SQL operation is an essential tool for database queries that combine results from multiple SELECT statements. It’s invaluable when working with complex data structures, allowing developers to merge rows......
Eloquent error: Cannot add a NOT NULL column with default value NULL
Updated: Jan 17, 2024
The Problem When working with Laravel’s Eloquent ORM to handle Database interactions, developers might sometimes run into this particular error message: Cannot add a NOT NULL column with default value NULL. This error typically......
Laravel Eloquent: Change format of created_at and updated_at columns
Updated: Jan 17, 2024
Overview Laravel is widely recognized for its elegant handling of database operations, largely attributed to its built-in ORM, Eloquent. A common requirement in web development is to format or mutate the date columns such as created_at......
Laravel Eloquent: Change column type with migration
Updated: Jan 17, 2024
Introduction Laravel’s Eloquent ORM provides an elegant and efficient way to interact with your database. However, there might come a time when you need to change the type of a column in your table, and Laravel’s migrations......