From 38e5fc43ebc59986a598f46757d6e7e6c751073c Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sun, 25 Jul 2021 05:46:42 -0600 Subject: [PATCH] Add FollowObserver --- app/Observers/FollowerObserver.php | 64 ++++++++++++++++++++++++++++ app/Providers/AppServiceProvider.php | 3 ++ 2 files changed, 67 insertions(+) create mode 100644 app/Observers/FollowerObserver.php diff --git a/app/Observers/FollowerObserver.php b/app/Observers/FollowerObserver.php new file mode 100644 index 000000000..afc476eeb --- /dev/null +++ b/app/Observers/FollowerObserver.php @@ -0,0 +1,64 @@ +profile_id, $follower->following_id); + } + + /** + * Handle the Follower "updated" event. + * + * @param \App\Models\Follower $follower + * @return void + */ + public function updated(Follower $follower) + { + FollowerService::add($follower->profile_id, $follower->following_id); + } + + /** + * Handle the Follower "deleted" event. + * + * @param \App\Models\Follower $follower + * @return void + */ + public function deleted(Follower $follower) + { + FollowerService::remove($follower->profile_id, $follower->following_id); + } + + /** + * Handle the Follower "restored" event. + * + * @param \App\Models\Follower $follower + * @return void + */ + public function restored(Follower $follower) + { + FollowerService::add($follower->profile_id, $follower->following_id); + } + + /** + * Handle the Follower "force deleted" event. + * + * @param \App\Models\Follower $follower + * @return void + */ + public function forceDeleted(Follower $follower) + { + FollowerService::remove($follower->profile_id, $follower->following_id); + } +} diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index a4dfbe27b..f2baf4c88 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -4,6 +4,7 @@ namespace App\Providers; use App\Observers\{ AvatarObserver, + FollowerObserver, LikeObserver, NotificationObserver, ModLogObserver, @@ -14,6 +15,7 @@ use App\Observers\{ }; use App\{ Avatar, + Follower, Like, Notification, ModLog, @@ -48,6 +50,7 @@ class AppServiceProvider extends ServiceProvider StatusHashtag::observe(StatusHashtagObserver::class); User::observe(UserObserver::class); UserFilter::observe(UserFilterObserver::class); + Follower::observe(FollowerObserver::class); Horizon::auth(function ($request) { return Auth::check() && $request->user()->is_admin; });