Summer sale! Save 50% on access to our entire library of courses.Join here →

Articles

Showing 10 posts
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
May 21st, 2024

How to Use Casts Inside a Laravel Trait

If you move over some functionality to a trait in Laravel that requires casts to be added as part of the trait's functionality, this won't merge by default.

Author
Alex Garrett-Smith
Laravel
Eloquent
May 19th, 2024

Eloquent Events on Pivot Tables

I recently needed to listen to events on a pivot table within the Codecourse codebase. When a user resets progress for a course, and all the episodes they've completed are detached, episode progress (stored in Redis) should be removed.

Author
Alex Garrett-Smith
Laravel
Eloquent
May 18th, 2024

Using the Booted Method Inside Traits in Laravel

Extracting some functionality to a trait but need to use the static booted method within that trait? Here's how.

Author
Alex Garrett-Smith
Eloquent
Laravel
April 18th, 2024

How to get the table name from a model in Laravel

Table names don't change often, but it's still nice to reference table names directly from your Eloquent models, so you don't end up with a bunch of hardcoded table names.

Author
Alex Garrett-Smith
Eloquent
Laravel
March 14th, 2024

How to Paginate a Laravel Collection

If you're merging multiple models into a Laravel collection or just have a collection of data you need to paginate, here's an easy, clean way to do it.

Author
Alex Garrett-Smith
Laravel
Eloquent

Tags