From 61911d5cdb962e7dd13e8ddeeade17cae514424d Mon Sep 17 00:00:00 2001 From: mahdihty Date: Tue, 16 Mar 2021 19:22:07 +0330 Subject: [PATCH] send socket notif in info method and notif handler listener --- app/Listeners/NotifHandler.php | 8 +++++++- app/Models/Business.php | 4 ++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/app/Listeners/NotifHandler.php b/app/Listeners/NotifHandler.php index 1fed4db..c53def9 100644 --- a/app/Listeners/NotifHandler.php +++ b/app/Listeners/NotifHandler.php @@ -3,8 +3,10 @@ namespace App\Listeners; use App\Events\ModelSaved; +use App\Notifications\SocketNotification; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Queue\InteractsWithQueue; +use Illuminate\Support\Facades\Notification; class NotifHandler { @@ -29,8 +31,12 @@ class NotifHandler $message = json_decode($event->message); $event_class = 'App\Events\\'.enum('tables.'.$message->data->table_name.'.singular_name').enum('cruds.inverse.'.$message->data->crud_id.'.name'); if (class_exists($event_class)) { -// event(new ('App\Events\\'.$event_class($message))); $event_class::dispatch($message); } + Notification::send(auth()->user(), new SocketNotification( + [ + 'message' => enum('tables.'.$message->data->table_name.'.singular_name').enum('cruds.inverse.'.$message->data->crud_id.'.name'), + 'payload'=>$business_info + ])); } } diff --git a/app/Models/Business.php b/app/Models/Business.php index 80e869f..e308bad 100644 --- a/app/Models/Business.php +++ b/app/Models/Business.php @@ -5,6 +5,8 @@ namespace App\Models; use App\Models\File; use App\Models\Model; use App\Models\SoftDeletes; +use App\Notifications\SocketNotification; +use Illuminate\Support\Facades\Notification; use Illuminate\Validation\Rule; use Illuminate\Http\UploadedFile; use Spatie\MediaLibrary\HasMedia; @@ -234,6 +236,8 @@ class Business extends Model implements HasMedia Cache::put('business_info'.$businessId , $business_info, config('app.cache_ttl')); + Notification::send(auth()->user(), new SocketNotification(['message' => 'business info update','payload'=>$business_info])); + return $business_info; }