Source: 63ed317ce2b8760008fb2e0a--sebastiandedeyne-com-e11d52.netlify.app

Granular interfaces
It was food for thought about the flexibility granular interfaces provide, and choosing the right abstraction at the right time. First, we’ll create a course object with a Purchasable interface to indicate it can be purchased, and a Registrable interface to indicate a registration should be created after the customer has paid.

class Bundle implements Product, CreatesRegistrations public function __construct( public array $courses public function createsRegistrationsFor(): array return $this->courses; In our checkout code, we add another check for the new interface.

If we want to know wether a product will create a registration, we have to check for both the Registrable and CreatesRegistrations interfaces.

class Course implements Product, Registrable, CreatesRegistrations public function providesRegistrationsFor(): array return [$this]; And we can revert our checkout code is back to one createRegistration call.
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future. Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future.
Community Partners