Skip to content

Commit

Permalink
feat: add item observer
Browse files Browse the repository at this point in the history
  • Loading branch information
phojie committed Dec 4, 2022
1 parent b180475 commit a439e81
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
20 changes: 20 additions & 0 deletions app/Observers/ItemObserver.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace App\Observers;

use App\Models\Item;

class ItemObserver
{
public function deleted(Item $item): void
{
$item->status = 'deleted';
$item->save();
}

public function restored(Item $item): void
{
$item->status = 'active';
$item->save();
}
}
5 changes: 4 additions & 1 deletion app/Providers/EventServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
namespace App\Providers;

use App\Models\Category;
use App\Models\Item;
use App\Models\User;
use App\Observers\CategoryObserver;
use App\Observers\ItemObserver;
use App\Observers\UserObserver;
use Illuminate\Auth\Events\Registered;
use Illuminate\Auth\Listeners\SendEmailVerificationNotification;
Expand Down Expand Up @@ -36,7 +38,8 @@ public function boot()

protected $observers = [
User::class => [UserObserver::class],
Category::class => [CategoryObserver::class],
Category::class => [CategoryObserver::class],
Item::class => [ItemObserver::class],
];

/**
Expand Down

0 comments on commit a439e81

Please sign in to comment.