Category: eloquent

Re-Introducing Eloquent’s Polymorphic Relationships

You’ve probably used different types of relationships between models or database tables, like those commonly seen in Laravel: one-to-one, one-to-many, many-to-many, and has-many-through. But there’s another type of relationship that’s not so common: polymorphic. So what is a polymorphic relationship? ...

What Are Polymorphic Relations and How Do We Use Them with Eloquent?

While I was working on an application for a client, I had to implement a new module that entails the following: Users ask for a budget quotation for a certain task. Every task has a location. Professionals can subscribe to different zones. A zone can be a region or a city. Now, let’s neglect the core applicatio...

Quick Tip: The Convenient Magic of Eloquent Observers

If you’ve used Eloquent on medium to large projects before, you may have encountered a situation where you want to take action when something happens to your models. Eloquent provides a convenient way to do so. The Observer Pattern The observer pattern is a software design pattern in which an object, called the...

Extending OctoberCMS – Building a Soft-Delete Plugin

Developers usually stick with a new CMS for its simplicity and extensibility. OctoberCMS presents itself as a back to basics CMS, and provides an enjoyable experience for both developers and users. In this article, I’m going to demonstrate some aspects of the CMS that makes it extensible, and we’ll also try...

Modeling an Aggregate with Eloquent

The Aggregate pattern is an important part of Domain Driven Design. It prevents inconsistencies and is responsible for enforcing business rules within a collection of objects. For these reasons alone, it is clear to see why it is a key component of a domain model. Architectural advice recommends that the layer containi...