> For the complete documentation index, see [llms.txt](https://docs.opensoutheners.com/home/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.opensoutheners.com/home/laravel-scim/events.md).

# Events

The package dispatches Laravel events during SCIM resource lifecycle operations. Use these to hook into provisioning actions without modifying the core code.

## Available events

### Create resource (POST)

| Event                 | When                             |
| --------------------- | -------------------------------- |
| `scim.model.saving`   | Before saving (create or update) |
| `scim.model.creating` | Before creating a new model      |
| `scim.model.created`  | After the model is created       |
| `scim.model.saved`    | After saving (create or update)  |

### Update resource (PUT/PATCH)

| Event                 | When                              |
| --------------------- | --------------------------------- |
| `scim.model.saving`   | Before saving                     |
| `scim.model.updating` | Before updating an existing model |
| `scim.model.updated`  | After the model is updated        |
| `scim.model.saved`    | After saving                      |

### Delete resource (DELETE)

| Event                 | When                       |
| --------------------- | -------------------------- |
| `scim.model.deleting` | Before deleting the model  |
| `scim.model.deleted`  | After the model is deleted |

## Listening to events

Register listeners in a service provider:

```php
use Illuminate\Support\Facades\Event;

Event::listen('scim.model.creating', function ($model) {
    // Set defaults for SCIM-provisioned users
    $model->source = 'scim';
});

Event::listen('scim.model.created', function ($model) {
    // Send welcome notification
    if ($model instanceof User) {
        $model->notify(new WelcomeNotification());
    }
});

Event::listen('scim.model.deleting', function ($model) {
    // Soft-delete instead of hard-delete
    // Or run cleanup logic
    Log::info("SCIM deleting {$model->getTable()} #{$model->getKey()}");
});
```

## Execution order

For a create operation:

```
Gate check → Validate request → Create schema
→ scim.model.saving → scim.model.creating
→ Model saved to database
→ scim.model.created → scim.model.saved
→ Sync relationships → Return response
```

For an update:

```
Gate check → Validate request → Create schema
→ scim.model.saving → scim.model.updating
→ Model saved to database
→ scim.model.updated → scim.model.saved
→ Sync relationships → Return response
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.opensoutheners.com/home/laravel-scim/events.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
