Observers
Introduction
Entry observers extend base observers.
Observers{.link}
Defining Observers
Entry entry
model observers are typically generated automatically when using make:stream
Streams CLI command.
CLI Commands{.link}
<?php namespace Anomaly\ExampleModule\Example;
use Anomaly\Streams\Platform\Entry\EntryObserver;
use Anomaly\Streams\Platform\Entry\Contract\EntryInterface;
class ExampleObserver extends EntryObserver
{
//
}
Registering Observers
Entry model observers are registered automatically via class transformation.
You can register additional observers if needed from your addon service provider.
Service Providers{.link}
<?php namespace Anomaly\ExampleTheme;
use Anomaly\ExampleModule\Example\ExampleModel;
use Anomaly\ExampleTheme\Observer\ExampleObserver;
use Anomaly\Streams\Platform\Addon\AddonServiceProvider;
class ExampleThemeServiceProvider extends AddonServiceProvider
{
public function register()
{
//
}
public function boot()
{
ExampleModel::observe(ExampleObserver::class);
}
}
Events
All entry models support the eloquent model observer events and also add a couple entry model only events.
Creating
This event is fired just before the entry
is created.
public function creating(EntryInterface $entry)
{
// Do stuff.
parent::creating($entry);
}
Created
This event is fired just after the entry
is created.
public function creating(EntryInterface $entry)
{
// Do stuff.
parent::creating($entry);
}
Updating
This event is fired just before the entry
is updated.
public function updating(EntryInterface $entry)
{
// Do stuff.
parent::updating($entry);
}
Updated
This event is fired just after the entry
is updated.
public function updating(EntryInterface $entry)
{
// Do stuff.
parent::updating($entry);
}
Updated Many
This event is fired just after the table corresponding to entry
is mass updated.
public function updatedMultiple(EntryInterface $entry)
{
// Do stuff.
parent::updatedMultiple($entry);
}
Saving
This event is fired just before the entry
is saved.
public function saving(EntryInterface $entry)
{
// Do stuff.
parent::saving($entry);
}
Saved
This event is fired just after the entry
is saved.
public function saving(EntryInterface $entry)
{
// Do stuff.
parent::saving($entry);
}
Deleting
This event is fired just before the entry
is deleted.
public function deleting(EntryInterface $entry)
{
// Do stuff.
parent::deleting($entry);
}
Deleted
This event is fired just after the entry
is deleted.
public function deleting(EntryInterface $entry)
{
// Do stuff.
parent::deleting($entry);
}
Deleted Many
This event is fired just after the table corresponding to entry
is mass deleted.
public function deletedMultiple(EntryInterface $entry)
{
// Do stuff.
parent::deletedMultiple($entry);
}
Restoring
This event is fired just before the entry
is restored.
public function restoring(EntryInterface $entry)
{
// Do stuff.
parent::restoring($entry);
}
Restored
This event is fired just after the entry
is restored.
public function restoring(EntryInterface $entry)
{
// Do stuff.
parent::restoring($entry);
}