77use App \Enums \PluginTier ;
88use App \Enums \PluginType ;
99use App \Enums \PriceTier ;
10+ use App \Notifications \NewPluginAvailable ;
1011use App \Notifications \PluginApproved ;
1112use App \Notifications \PluginRejected ;
1213use App \Services \PluginSyncService ;
2021use Illuminate \Database \Eloquent \Relations \BelongsToMany ;
2122use Illuminate \Database \Eloquent \Relations \HasMany ;
2223use Illuminate \Database \Eloquent \Relations \HasOne ;
24+ use Illuminate \Support \Facades \Notification ;
2325
2426class Plugin extends Model
2527{
@@ -537,6 +539,7 @@ public function getRepositoryOwnerAndName(): ?array
537539 public function approve (int $ approvedById ): void
538540 {
539541 $ previousStatus = $ this ->status ;
542+ $ isFirstApproval = $ this ->approved_at === null ;
540543
541544 $ this ->update ([
542545 'status ' => PluginStatus::Approved,
@@ -555,6 +558,15 @@ public function approve(int $approvedById): void
555558
556559 $ this ->user ->notify (new PluginApproved ($ this ));
557560
561+ if ($ isFirstApproval ) {
562+ $ recipients = User::query ()
563+ ->where ('receives_new_plugin_notifications ' , true )
564+ ->where ('id ' , '!= ' , $ this ->user_id )
565+ ->get ();
566+
567+ Notification::send ($ recipients , new NewPluginAvailable ($ this ));
568+ }
569+
558570 resolve (PluginSyncService::class)->sync ($ this );
559571 }
560572
0 commit comments