Eloquent

Laravel Shareable Models Package
Laravel Packages / September 04, 2017

Laravel Shareable Models Package

The Laravel Shareable Models package allows you to generate shareable links from your Eloquent models. Think dynamic routes which only exist for models that have been shared. The package author Kai Sassnowski described his use-case for the Shareable Models package as follows: My initial use case was giving certain non-admin user access to a certain …

Optimize Laravel Eloquent Queries with Eager Loading
Laravel Tutorials / August 07, 2017

Optimize Laravel Eloquent Queries with Eager Loading

Learn how to optimize your related model queries in Laravel with eager loading. We will set up some example relationships and then walk through how queries change with and without eager loading. I like to get my hands directly on code and experiment with things, and I hope to illustrate how eager loading works with some examples will further help you understand how to optimize your queries.

Read more…
Laravel 5.5 Pivot Casting
Laravel 5.5 / July 05, 2017

Laravel 5.5 Pivot Casting

A new addition to Laravel 5.5 will add support for pivot table casts when inserting & updating data on an intermediate table model.

Read more…
Laravel Eloquent Relationships Through Macros
Laravel 5.4 / February 02, 2017

Laravel Eloquent Relationships Through Macros

A new feature just merged into Laravel and included in the v5.4.8 update is the ability to define Macros for Eloquent Relationships. To better show how this feature works here is a screenshot by Jordan Pittman who created the original pull request: Here is that same example in a copy and paste friendly version. AppServiceProvider …

Quickly Dumping Laravel Queries
Laravel Tutorials / November 27, 2016

Quickly Dumping Laravel Queries

When you are building an application and utilizing Eloquent it’s very easy to hit the N+1 problem. This is where you select a model and then later use lazy loading to fetch child records. As an example pretend you are selecting a user: User::where(‘name’, ‘Eric’)->first(); Then in your view you might do something like: @foreach … Continue reading Read more…

Easily deleting old soft-deleted records with Quicksand
Laravel Packages / August 31, 2016

Easily deleting old soft-deleted records with Quicksand

When building applications, there are times when you would like to allow users to remove data from their view but keep the record in the database. An example could be allowing a user to delete their account, but you want to give them the opportunity to restart it later. If all their data is completely … Continue reading Easily deleting old so... Read more…

Laravel Packages / May 17, 2016

Query Tracer Package

Laravel Query Tracer is a new package by Trevor Fitzgerald that allows you to find exactly where a query is being called in your app. It works by tapping into Laravel’s global query scopes to do a backtrace and find where a query originated. The package ships with support for the Laravel Debugbar, Clockwork, or … Continue reading Query Tracer PackageRead more…

Laravel Packages / May 04, 2016

Cascading soft deletes with Eloquent

Michael Dyrynda has a new package for cascading soft deletes with Laravel and Eloquent. In scenarios when you delete a parent record – say for example a blog post – you may want to also delete any comments associated with it as a form of self-maintenance of your data. Normally, you would use your database’s … Continue reading Cascading soft... Read more…

Laravel Packages / December 04, 2015

Eloquence Package hits V2

Eloquence is a package to extend Laravel 5’s base Eloquent models and it has just hit version 2. Some of the features of the package include: True camelCase support for your model attributes A count cache for related models A sum cache for related models uuids and more… Version 2 features API improvements, a sum … Continue reading Eloquence Package hits V2Read more…

Laravel Tutorials / September 30, 2015

Learn about pivot tables and many-to-many relationships

Laravel Daily has a new post on pivot tables and many-to-many relationships: I want to talk about a feature of Laravel which is really useful but can be potentially difficult to understand at first. A pivot table is an example of intermediate table with relationships between two other “main” tables. This is a feature that … Continue reading Read more…