resources/boost/skills/observers/SKILL.md
Centralised classes that react to Eloquent model lifecycle events. Used for side effects that should always fire regardless of where a model is mutated — such as notifications, cache invalidation, and audit logging.
npx skillsauth add codebar-ag/coding-guidelines observersInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
app/Observers/PascalCase with an Observer suffix, named after the model they observe: UserObserver, InvoiceObserverAppServiceProvider using the observe() methodnamespace App\Observers;
use App\Models\User;
use App\Notifications\WelcomeNotification;
use Illuminate\Support\Facades\Cache;
class UserObserver
{
public function created(User $user): void
{
$user->notify(new WelcomeNotification());
}
public function updated(User $user): void
{
Cache::forget("user:{$user->id}");
}
public function deleted(User $user): void
{
Cache::forget("user:{$user->id}");
}
}
// Registration in AppServiceProvider
use App\Models\User;
use App\Observers\UserObserver;
public function boot(): void
{
User::observe(UserObserver::class);
}
// Anti-pattern: observer used where explicit Action flow is required
class InvoiceObserver
{
public function updated(Invoice $invoice): void
{
if ($invoice->status === 'paid') {
app(SendPaidInvoiceEmail::class)->execute($invoice);
}
}
}
// Better: explicit flow in Action for predictable control
class MarkInvoicePaid
{
public function execute(Invoice $invoice): void
{
$invoice->update(['status' => 'paid']);
app(SendPaidInvoiceEmail::class)->execute($invoice);
}
}
Available lifecycle events:
| Method | Fires when... |
|---|---|
| creating | Before a model is first saved |
| created | After a model is first saved |
| updating | Before an existing model is saved |
| updated | After an existing model is saved |
| saving | Before creating or updating |
| saved | After creating or updating |
| deleting | Before a model is deleted |
| deleted | After a model is deleted |
| restoring | Before a soft-deleted model is restored |
| restored | After a soft-deleted model is restored |
creating, updating, saving, deleting, and restoring run before persistence and may cancel the operation by returning false when needed.
Models/SKILL.md — Eloquent model conventionsEvents/SKILL.md — alternative for decoupled side effectstesting
Translation and localization conventions for Laravel. Use when adding user-facing strings, creating translation files, or working with lang/ directory.
tools
Reusable behaviour shared across multiple unrelated classes. Traits provide shared Eloquent scopes, accessors, lifecycle hooks, and small stateless helper methods.
development
Tailwind CSS v4 styling conventions. Use when working with CSS, Tailwind utilities, or customizing the theme in Laravel projects.
development
Orchestration classes that coordinate multiple Actions, external APIs, or domain operations into a cohesive workflow. Services own transaction boundaries and third-party API integrations.