Laravel Fireable Attributes
Published on by Paul Redmond
Laravel Fireable is a package by Boris Lepikhin that provides “an elegant way to trigger Laravel events based on attributes changes.”
Here’s an example from the project’s documentation that shows how this package works. In this example, updating a user’s status attribute triggers a UserApproved
event:
class User extends Authenticatable{ use FireableAttributes; protected $fireableAttributes = [ 'status' => [ 'approved' => UserApproved::class, 'rejected' => UserRejected::class, ], ];}
In some cases, you want to trigger an event whenever an attribute is changed regardless of its value:
class User extends Authenticatable{ use FireableAttributes; protected $fireableAttributes = [ 'email' => EmailUpdated::class, ];}
To learn more about this package, get full installation instructions, and view the source code on GitHub at envant/fireable.