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.
51 lines
1.3 KiB
51 lines
1.3 KiB
<?php
|
|
|
|
namespace App\Listeners;
|
|
|
|
use App\Events\BusinessUserCreate;
|
|
use App\Models\Business;
|
|
use App\Models\User;
|
|
use App\Utilities\HelperClass\NotificationHelper;
|
|
|
|
class BusinessUserCreateNotif
|
|
{
|
|
|
|
/**
|
|
* @var NotificationHelper
|
|
*/
|
|
public $helper;
|
|
|
|
/**
|
|
* Create the event listener.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function __construct(NotificationHelper $helper)
|
|
{
|
|
$this->helper = $helper;
|
|
}
|
|
|
|
/**
|
|
* Handle the event.
|
|
*
|
|
* @param BusinessUserCreate $event
|
|
* @return void
|
|
*/
|
|
public function handle(BusinessUserCreate $event)
|
|
{
|
|
$payload = $event->message;
|
|
if ($payload->data->original->level === enum('levels.inactive.id')) {
|
|
// When user level in business is zero, probably user added to business by system
|
|
// And not necessary send notification to stockholders
|
|
return;
|
|
}
|
|
$new_user = User::findOrFail($payload->data->original->user_id);
|
|
$owners = Business::findOrFail($payload->business)->owners()->where('id', '!=', $new_user->id)->get();
|
|
|
|
$users = $owners->prepend($new_user);
|
|
|
|
$this->helper->makeNotif($payload, null,
|
|
['business' => request('_business_info')['name'], 'user' => $new_user->name]
|
|
)->sendNotifications($users, 'critical');
|
|
}
|
|
}
|