georgeff / event
Abstraction of the illuminate/events package
Installs: 3 126
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Requires
- illuminate/contracts: ~5.4|~5.5
- illuminate/support: ~5.4|~5.5
Requires (Dev)
- mockery/mockery: 0.9.*
- phpunit/phpunit: ~6.0
This package is auto-updated.
Last update: 2021-08-16 00:49:08 UTC
README
Usage
<?php
use Event\UserWasCreated;
use Georgeff\Event\GeneratesEvents;
use Georgeff\Event\GeneratorInterface;
use Illuminate\Database\Eloquent\Model;
class User extends Model implements GeneratorInterface
{
use GeneratesEvents;
public static function create(array $data)
{
$user = new static;
$user->name = $data['name'];
$user->email = $data['email'];
$this->raise(new UserWasCreated($user));
return $this;
}
}
<?php
use Model\User;
use Georgeff\Event\Event;
class UserController extends Controller
{
protected $event;
public function __construct(Event $event)
{
$this->event = $event;
}
public function create()
{
$data = [
'name' => 'Tim',
'email' => 'tim@mail.com'
];
$user = User::create($data);
$user->save();
$this->event->dispatchFor($user);
...
}
}