Skip to content
sarfraznawaz2005Public

About

Laravel package to easily add event listening capabilities to any model on Create/Update/Delete operations.

Topics

Resources

Stars

3 stars

Watchers

1 watching

Forks

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 

Repository files navigation

Laravel Eventable

laravel 5.1 laravel 5.2 laravel 5.3 laravel 5.4 downloads

Introduction

Simple Laravel 5 package to easily add event listening capabilities to any model on Create/Update/Delete operations.

Requirements

  • PHP >= 5.6
  • Laravel 5

Installation

Install via composer

composer require sarfraznawaz2005/eventable

That's it!

Usage

Suppose you have a model called Task and you want to be able to do something when it's created/updated or deleted. To do that, just use the Eventable trait like so:

...
use Sarfraznawaz2005\Eventable\Eventable;

class Task extends Model
{
    use Eventable;
    
    ...
}

Now somewhere in your app, you can listen to events and do whatever you want:

Event::listen('task.created', function ($task) {
    // do something when task is created. In this case, just log it.
    Log::info('Task with id ' . $task->id . ' was created.');
});

Event::listen('task.updated', function ($task) {
    // do something when task is updated. In this case, just log it.
    Log::info('Task with id ' . $task->id . ' was updated.');
});

Event::listen('task.deleted', function ($task) {
    // do something when task is deleted. In this case, just log it.
    Log::info('Task with id ' . $task->id . ' was deleted.');
});

Note: Make sure your put event listening logic BEFORE saving/updating/deletng model logic.

License

This code is published under the MIT License. This means you can do almost anything with it, as long as the copyright notice and the accompanying license file is left intact.

About

Laravel package to easily add event listening capabilities to any model on Create/Update/Delete operations.

Topics

Resources

Stars

3 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages