All Projects â†’ jpkleemans â†’ attribute-events

jpkleemans / attribute-events

Licence: MIT License
🔥 Fire events on attribute changes of your Eloquent model

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to attribute-events

Library
This is a project of a library, driven by real business requirements. We use techniques strongly connected with Domain Driven Design, Behavior-Driven Development, Event Storming, User Story Mapping.
Stars: ✭ 2,685 (+1256.06%)
Mutual labels:  events, ddd, domain-driven-design, event-storming
Event Sourcing Cqrs Examples
Event Sourcing and CQRS in practice.
Stars: ✭ 265 (+33.84%)
Mutual labels:  events, ddd, domain-driven-design
Goes
Go Event Sourcing made easy
Stars: ✭ 144 (-27.27%)
Mutual labels:  events, ddd, domain-driven-design
All Things Cqrs
Comprehensive guide to a couple of possible ways of synchronizing two states with Spring tools. Synchronization is shown by separating command and queries in a simple CQRS application.
Stars: ✭ 474 (+139.39%)
Mutual labels:  events, ddd, domain-driven-design
Eventflow
Async/await first CQRS+ES and DDD framework for .NET
Stars: ✭ 1,932 (+875.76%)
Mutual labels:  events, ddd, domain-driven-design
DDD
Domain-Driven Design is a software development approach in which it utilizes concepts and good practices related to object-oriented programming.
Stars: ✭ 51 (-74.24%)
Mutual labels:  ddd, domain-driven-design
DDDToolbox
A set of Roslyn refactorings supporting DDD design
Stars: ✭ 31 (-84.34%)
Mutual labels:  ddd, domain-driven-design
laravel-boolean-dates
Automatically convert Eloquent model boolean attributes to dates (and back).
Stars: ✭ 31 (-84.34%)
Mutual labels:  eloquent, attributes
library-php
WIP: A comprehensive Domain-Driven Design example with problem space strategic analysis and various tactical patterns.
Stars: ✭ 73 (-63.13%)
Mutual labels:  events, domain-driven-design
eventuous
Minimalistic Event Sourcing library for .NET
Stars: ✭ 236 (+19.19%)
Mutual labels:  ddd, domain-driven-design
Plastic
This project provides encapsulation of things like Domain, Application Rules, Business Rules or Business Logic in Application.
Stars: ✭ 30 (-84.85%)
Mutual labels:  ddd, domain-driven-design
delta
DDD-centric event-sourcing library for the JVM
Stars: ✭ 15 (-92.42%)
Mutual labels:  ddd, domain-driven-design
Clean-Architecture-Template
Configurable Clean Architecture template containing the DDD + CQRS approach for .NET Core applications.
Stars: ✭ 14 (-92.93%)
Mutual labels:  ddd, domain-driven-design
typescript-ddd-example
🔷🎯 TypeScript DDD Example: Complete project applying Hexagonal Architecture and Domain-Driven Design patterns
Stars: ✭ 607 (+206.57%)
Mutual labels:  ddd, domain-driven-design
teamo-ddd-example
Implementing Domain Driven Design in PHP using Laravel
Stars: ✭ 46 (-76.77%)
Mutual labels:  ddd, domain-driven-design
MonolithicArchitecture
This repository presents an approach on how to build an application using Monolithic architecture, ASP.NET Core, EntityFrameworkCore, Identity Server, CQRS, DDD
Stars: ✭ 18 (-90.91%)
Mutual labels:  ddd, domain-driven-design
CQELight
CQELight is an entreprise grade extensible and customisable framework for creating software with CQRS, DDD & Event Sourcing patterns
Stars: ✭ 21 (-89.39%)
Mutual labels:  events, ddd
clean-ddd-php-poc-contacts
A simple contact manager API to demonstrate the concepts of Clean Architecture and DDD with PHP 7.4+.
Stars: ✭ 31 (-84.34%)
Mutual labels:  ddd, domain-driven-design
tradeio
A disciplined way to purely functional domain models in Scala
Stars: ✭ 19 (-90.4%)
Mutual labels:  ddd, domain-driven-design
vcenter-event-broker-appliance
The VMware Event Broker Appliance Fling enables customers to unlock the hidden potential of events in their SDDC to easily create event-driven automation.
Stars: ✭ 120 (-39.39%)
Mutual labels:  events, event-driven-architecture

Laravel Attribute Events Laravel Attribute Events

Build Status Last Updated Latest Stable Version License

class Order extends Model
{
    protected $dispatchesEvents = [
        'status:shipped' => OrderShipped::class,
        'note:*' => OrderNoteChanged::class,
    ];
}

Eloquent models fire several handy events throughout their lifecycle, like created and deleted. However, there are usually many more business meaningful events that happen during a model's life. With this library you can capture those, by mapping attribute changes to your own event classes.

Installation

composer require jpkleemans/attribute-events

How to use it

Use the Kleemans\AttributeEvents trait in your model and add the attributes to the $dispatchesEvents property:

class Order extends Model
{
    use AttributeEvents;

    protected $dispatchesEvents = [
        'created'         => OrderPlaced::class,
        'status:canceled' => OrderCanceled::class,
        'note:*'          => OrderNoteChanged::class,
    ];
}

The attribute events will be dispatched after the updated model is saved. Each event receives the instance of the model through its constructor.

For more info on model events and the $dispatchesEvents property, visit the Laravel Docs

Listening

Now you can subscribe to the events via the EventServiceProvider $listen array, or manually with Closure based listeners:

Event::listen(function (OrderCanceled $event) {
    // Restock inventory
});

Or push realtime updates to your users, using Laravel's broadcasting feature:

Echo.channel('orders')
    .listen('OrderShipped', (event) => {
        // Display a notification
    })

JSON attributes

For attributes stored as JSON, you can use the -> operator:

protected $dispatchesEvents = [
    'payment->status:completed' => PaymentCompleted::class,
];

Accessors

For more complex state changes, you can use attributes defined by an accessor:

class Product extends Model
{
    protected $dispatchesEvents = [
        'low_stock:true' => ProductReachedLowStock::class,
    ];

    public function getLowStockAttribute(): bool
    {
        return $this->stock <= 3;
    }
}

You can also use the new way of defining accessors introduced in Laravel 9.

Sponsors

Nexxtmove Logo

Thanks to Nexxtmove for sponsoring the development of this project.

License

Code released under the MIT License.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].