Explorar o código

Add empty CommentAdded event and PremoderateComment listener

axkuhta hai 1 ano
pai
achega
f058a2f5ba

+ 36 - 0
app/Events/CommentAdded.php

@@ -0,0 +1,36 @@
+<?php
+
+namespace App\Events;
+
+use Illuminate\Broadcasting\Channel;
+use Illuminate\Broadcasting\InteractsWithSockets;
+use Illuminate\Broadcasting\PresenceChannel;
+use Illuminate\Broadcasting\PrivateChannel;
+use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
+use Illuminate\Foundation\Events\Dispatchable;
+use Illuminate\Queue\SerializesModels;
+
+class CommentAdded
+{
+    use Dispatchable, InteractsWithSockets, SerializesModels;
+
+    /**
+     * Create a new event instance.
+     */
+    public function __construct()
+    {
+        //
+    }
+
+    /**
+     * Get the channels the event should broadcast on.
+     *
+     * @return array<int, \Illuminate\Broadcasting\Channel>
+     */
+    public function broadcastOn(): array
+    {
+        return [
+            new PrivateChannel('channel-name'),
+        ];
+    }
+}

+ 26 - 0
app/Listeners/PremoderateComment.php

@@ -0,0 +1,26 @@
+<?php
+
+namespace App\Listeners;
+
+use App\Events\CommentAdded;
+use Illuminate\Contracts\Queue\ShouldQueue;
+use Illuminate\Queue\InteractsWithQueue;
+
+class PremoderateComment
+{
+    /**
+     * Create the event listener.
+     */
+    public function __construct()
+    {
+        //
+    }
+
+    /**
+     * Handle the event.
+     */
+    public function handle(CommentAdded $event): void
+    {
+        //
+    }
+}

+ 9 - 0
app/Providers/EventServiceProvider.php

@@ -7,6 +7,11 @@ use Illuminate\Auth\Listeners\SendEmailVerificationNotification;
 use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
 use Illuminate\Support\Facades\Event;
 
+// Указывают *где* нужно расположить файлы для новых классов
+// Если пропустить эти строки, то будет использован NS App\Providers
+use App\Events\CommentAdded;
+use App\Listeners\PremoderateComment;
+
 class EventServiceProvider extends ServiceProvider
 {
     /**
@@ -18,6 +23,10 @@ class EventServiceProvider extends ServiceProvider
         Registered::class => [
             SendEmailVerificationNotification::class,
         ],
+
+		CommentAdded::class => [
+			PremoderateComment::class
+		]
     ];
 
     /**