Laravel 12 Eloquent: Expert Level
The no.1 topic of Laravel-related questions I get is about Eloquent. How to query X? What's the bes...
We found 32 results for "eloquent".
The no.1 topic of Laravel-related questions I get is about Eloquent. How to query X? What's the bes...
When it comes to the performance of the Laravel application, by far the no.1 problem I've seen is the database. DB Structure, Eloquent/SQL queries, and configuration - they all may cause many issues, so in this article, I've tried to compile "the ultimate guide" of what you need to know.
I've talked a lot about Eloquent on this channel but decided to pick the three most common mistakes related to performance.
This video is a 4-in-1 lesson from my course "Eloquent: Expert Level" about N+1 Query Problem.
Eloquent is a great feature of Laravel, but also great is the list of packages that add more features on top of the framework. Let's explore them, in this article! The title says 20 packages, but there are quite a few alternatives mentioned along the way, so the actual number is even bigger than this. Ready? Let's jump in!
Sometimes, you may need to make a copy of an Eloquent Model object to clone it. For example, you have similar products; the only difference is the specific options inside. I will show you two ways.
Quite often in e-shops you can see many level of categories and subcategories, sometimes even unlimited. This article will show you how to achieve it elegantly with Laravel Eloquent in two methods.
Let's get a bit deeper into the topic of Soft Deletes. How can you query/restore the soft-deleted records? How do they work with Observers? How to cascade the soft-deletes?
A free lesson from my course "Structuring Databases in Laravel 11".
Example from open-source project on how NOT to do things in Eloquent.
Elegant, framework-agnostic approach to managing roles and abilities for any app using Eloquent models
This package can associate all sorts of files with Eloquent models
Filter, sort and include eloquent relations based on a request.
A practical dive into SQL queries - we launch a few Eloquent "magic methods" and see what database queries are actually running under the hood.
I've been asked this question quite a lot, so decided to discuss the pros and cons of each approach.
Today I'm answering an email with a question on how to avoid repeating similar conditions in three if-statements.
If you have a complex DB query with multiple AND/OR conditions, there's one mistake you need to avoid. In this video, I will show you what the mistake is, what is the bad result of it, and how to fix it.
I often hear an argument that there can be too many fields in the "users" DB table, so it's worth splitting it into two tables with the relationship. Let's take a look at one example, and I will share my thoughts.
Eloquent is a great thing - you can build your query step-by-step and then call get() method. But sometimes it gets a little tricky for more complicated queries - for example, if you have multiple AND-OR conditions and you want to put brackets, how to do it properly?
To add a record to the database, you may use one of two methods. What is the difference?
Many of us are used to write conditional Eloquent queries with "if-else". What if I told you there's a (much) better way? Easily readable and more Laravel-ish.
Quite often in bigger projects there are DB relationships with more than one level: categories->companies->products, countries->teams->players and similar. If we need to get the list of a deeper level, there's a quick way of doing that with Eloquent.
Let's say you want to filter out entries created today. You have a timestamp field created_at, right? How do you filter the DATE only from that timestamp? Apparently, Taylor thought about it.
Another "hidden gem" of Eloquent. Let's imagine that you want to query all rows from the table and also one related row - not all of them, but the newest one. Apparently, it's pretty easy.
Eloquent's missing "array" driver. Sometimes you want to use Eloquent, but without dealing with a database.
Brings STI (Single Table Inheritance) capabilities to Eloquent.
Easy creation of slugs for your Eloquent models in Laravel.
Generate slugs when saving Eloquent models
This extended version of HasManyThrough allows relationships with unlimited intermediate models.
Sortable behaviour for Eloquent models
Pragmatically search through models and other sources