---
title: Observers
---

# Observers

<div class="documentation__toc"></div>

## Introduction

Entry observers extend [base observers](../core-concepts/observers).

[Observers](../core-concepts/observers){.link}

### Defining Observers

Entry `entry` model observers are typically generated automatically when using `make:stream` Streams CLI command.

[CLI Commands](../reference/cli-commands#make-stream){.link}

```php
<?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](../the-basics/service-providers){.link}

```php
<?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.
 
```php
public function creating(EntryInterface $entry)
{
    // Do stuff.
    
    parent::creating($entry);
}
```

### Created

This event is fired just after the `entry` is created.
 
```php
public function created(EntryInterface $entry)
{
    // Do stuff.
    
    parent::created($entry);
}
```

### Updating

This event is fired just before the `entry` is updated.
 
```php
public function updating(EntryInterface $entry)
{
    // Do stuff.
    
    parent::updating($entry);
}
```

### Updated

This event is fired just after the `entry` is updated.
 
```php
public function updated(EntryInterface $entry)
{
    // Do stuff.
    
    parent::updated($entry);
}
```

### Updated Many

This event is fired just after the table corresponding to `entry` is mass updated.
 
```php
public function updatedMultiple(EntryInterface $entry)
{
    // Do stuff.
    
    parent::updatedMultiple($entry);
}
```

### Saving

This event is fired just before the `entry` is saved.
 
```php
public function saving(EntryInterface $entry)
{
    // Do stuff.
    
    parent::saving($entry);
}
```

### Saved

This event is fired just after the `entry` is saved.
 
```php
public function saved(EntryInterface $entry)
{
    // Do stuff.
    
    parent::saved($entry);
}
```

### Deleting

This event is fired just before the `entry` is deleted.
 
```php
public function deleting(EntryInterface $entry)
{
    // Do stuff.
    
    parent::deleting($entry);
}
```

### Deleted

This event is fired just after the `entry` is deleted.
 
```php
public function deleted(EntryInterface $entry)
{
    // Do stuff.
    
    parent::deleted($entry);
}
```

### Deleted Many

This event is fired just after the table corresponding to `entry` is mass deleted.
 
```php
public function deletedMultiple(EntryInterface $entry)
{
    // Do stuff.
    
    parent::deletedMultiple($entry);
}
```

### Restoring

This event is fired just before the `entry` is restored.
 
```php
public function restoring(EntryInterface $entry)
{
    // Do stuff.
    
    parent::restoring($entry);
}
```

### Restored

This event is fired just after the `entry` is restored.
 
```php
public function restored(EntryInterface $entry)
{
    // Do stuff.
    
    parent::restored($entry);
}
```
