Articles

Showing 10 posts
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
July 5th, 2024

Get the fillable array from a Laravel model

If, for any reason, you need to get the fillable fields from a Laravel model, it's pretty straightforward.

Author
Alex Garrett-Smith
Laravel
Eloquent
June 13th, 2024

Using Eloquent Outside of Laravel

It's pretty straightforward to use Eloquent outside of the Laravel Framework. Let's look at all the steps to get it working, whether you want to pull it into another framework or use it in procedural code.

Author
Alex Garrett-Smith
Eloquent
Laravel
May 22nd, 2024

Laravel Has Many Through Pivot Relationships

Laravel doesn't support has many through pivot relationships out the box, but we can still achieve this manually with a pivot model.

Author
Alex Garrett-Smith
Eloquent
Laravel

Tags