You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
1.2 KiB
44 lines
1.2 KiB
<?php
|
|
|
|
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
|
|
{
|
|
/**
|
|
* Create the event listener.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function __construct()
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Handle the event.
|
|
*
|
|
* @param ModelSaved $event
|
|
* @return void
|
|
*/
|
|
public function handle(ModelSaved $event)
|
|
{
|
|
$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_class::dispatch($message);
|
|
}
|
|
if (auth()->user()) {
|
|
Notification::send(auth()->user(), new SocketNotification(
|
|
[
|
|
'message' => enum('tables.'.$message->data->table_name.'.singular_name').enum('cruds.inverse.'.$message->data->crud_id.'.name'),
|
|
'payload'=> request('_business_info') ?? null
|
|
]));
|
|
}
|
|
}
|
|
}
|