From 54fc5e09c3502dd95769a597c7456ad7b72b2e07 Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Wed, 6 Nov 2024 17:05:04 +0100 Subject: [PATCH] wait #7178 @1.5 --- app/Http/Controllers/FluidbookController.php | 8 ++++++-- app/Models/User.php | 12 ++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/FluidbookController.php b/app/Http/Controllers/FluidbookController.php index 4ba1e06..39471ef 100644 --- a/app/Http/Controllers/FluidbookController.php +++ b/app/Http/Controllers/FluidbookController.php @@ -56,7 +56,11 @@ class FluidbookController extends Controller $client->enabled = false; $client->save(); - User::withoutGlobalScopes()->find(3)->notify(new ResahNotification(ResahNotification::ACCOUNT_CREATED, $client)); + try { + User::notifyAdmins(new ResahNotification(ResahNotification::ACCOUNT_CREATED, $client), 'client'); + } catch (\Exception $exception) { + + } return response()->json(['success' => 'ok'])->setStatusCode(200); @@ -187,7 +191,7 @@ class FluidbookController extends Controller $order->saveQuietly(); $user->notify(new ResahNotification(ResahNotification::QUOTE_REQUEST_SENT, $order)); - User::withoutGlobalScopes()->find(3)->notify(new ResahNotification(ResahNotification::QUOTE_REQUEST, $order)); + User::notifyAdmins(new ResahNotification(ResahNotification::QUOTE_REQUEST, $order), 'order'); return response()->json(['success' => 'ok', 'order' => $order->id, 'subTotal' => $total, 'taxes' => $cumul_tva, 'total' => $total + $cumul_tva])->setStatusCode(200); diff --git a/app/Models/User.php b/app/Models/User.php index 1187a8d..e8f8c8b 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -3,9 +3,21 @@ namespace App\Models; use Cubist\Backpack\Magic\Models\CubistMagicAuthenticatable; +use Illuminate\Notifications\Notification; class User extends CubistMagicAuthenticatable { + public static function notifyAdmins(Notification $notification, $type) + { + foreach (User::withoutGlobalScopes()->get() as $u) { + if (stristr($u->email, '@cubedesigners.com')) { + //continue; + } + if ($u->hasPermissionTo($type . ':notified')) { + $u->notify($notification); + } + } + } } -- 2.39.5