Flash sale! 50% off all-access lifetime membership.Join here →

Articles

Showing 10 posts
May 14th, 2025

Disable Event Dispatches when Creating Eloquent Models

Usually during testing, you may want to create a record using a model without dispatching events.

Author
Alex Garrett-Smith
Eloquent
Laravel
May 12th, 2025

How to Dump the Underlying SQL Query From Eloquent

Need to inspect the query being used by Eloquent? Here's how to reveal it.

Author
Alex Garrett-Smith
Eloquent
Laravel
May 9th, 2025

Removing Timestamp Columns from Eloquent Models

If you want to exclude the created_at and updated_at columns from a table and disable them in your Eloquent models, here's how.

Author
Alex Garrett-Smith
Eloquent
Laravel
February 5th, 2025

Laravel's incrementOrCreate Method

Added in Laravel 11, incrementOrCreate is a method to create a record uniquely based on a pre-defined array.

Author
Alex Garrett-Smith
Laravel
Eloquent
February 3rd, 2025

How to fix "Add [column] to fillable property to allow mass assignment on [Model]" in Laravel.

This mass assignment error is a really common one when working with Laravel. Here's how to fix the inability to insert/update records.

Author
Alex Garrett-Smith
Eloquent
Laravel
January 30th, 2025

How to Use updateOrCreate in Laravel

If you have a potentially existing record and need to update it if it exists or create it if it doesn't. Here's how!

Author
Alex Garrett-Smith
Eloquent
Laravel
January 30th, 2025

How to Cast Pivot Table Columns in Laravel

In this article, I'll show you how to set up casts for pivot table columns in your Laravel relationships.

Author
Alex Garrett-Smith
Eloquent
Laravel
September 16th, 2024

How to (Efficiently) Count Records with Laravel

There are several ways to get the row count from your database with Eloquent in Laravel. Let's cover the basics and then look at a much better solution when counting on related models — using aggregates at the database level.

Author
Alex Garrett-Smith
Eloquent
Laravel
July 15th, 2024

How to get the next and previous records in Laravel

Laravel doesn't have built-in support to fetch next and previous records, but adding a couple of helper methods to your model does the trick.

Author
Alex Garrett-Smith
Eloquent
Laravel
July 11th, 2024

How to Use orderBy() (and more) for Sorting Eloquent Query Results

Ordering in Laravel is pretty straightforward, but you can use a few other techniques to make the most of Eloquent's ordering abilities. Let's cover everything you should know about ordering queries with Laravel!

Author
Alex Garrett-Smith
Eloquent
Laravel

Tags