diff --git a/app/Filament/Resources/RfqTransporterBidResource/Pages/EditRfqTransporterBid.php b/app/Filament/Resources/RfqTransporterBidResource/Pages/EditRfqTransporterBid.php index 33887a2..6e2c357 100644 --- a/app/Filament/Resources/RfqTransporterBidResource/Pages/EditRfqTransporterBid.php +++ b/app/Filament/Resources/RfqTransporterBidResource/Pages/EditRfqTransporterBid.php @@ -4,6 +4,7 @@ namespace App\Filament\Resources\RfqTransporterBidResource\Pages; use App\Filament\Resources\RfqTransporterBidResource; use App\Models\RfqTransporterBid; +use App\Models\SpotRateTransportMaster; use App\Models\User; use App\Notifications\PushAlertNotification; use Filament\Actions; @@ -24,48 +25,78 @@ class EditRfqTransporterBid extends EditRecord // dd($this->record); $rank = RfqTransporterBid::where('request_quotation_id', $this->record->request_quotation_id) + ->where('spot_rate_transport_master_id', $this->record->spot_rate_transport_master_id) ->orderBy('total_freight_charge') ->pluck('id') ->search($this->record->id) + 1; - $recipients = User::role(['Super Admin', 'Rfq Supervisor', 'TransporterBid Employee'])->get(); + $spotRate = SpotRateTransportMaster::findOrFail( + $this->record->spot_rate_transport_master_id + ); - $recipients1 = User::role(['Super Admin', 'Rfq Supervisor', 'TransporterBid Employee'])->whereHas('pushSubscriptions')->get(); + $userNames = json_decode($spotRate->user_name, true); + if (!is_array($userNames)) { + $userNames = []; + } + + $users = User::whereIn('name', $userNames)->get(); + + + // $recipients = User::role(['Super Admin', 'Rfq Supervisor', 'TransporterBid Employee'])->get(); + + // $recipients1 = User::role(['Super Admin', 'Rfq Supervisor', 'TransporterBid Employee'])->whereHas('pushSubscriptions')->get(); $currentUser = Filament::auth()->user(); - if ($currentUser && ! $recipients1->contains('id', $currentUser->id)) { - $recipients1->push($currentUser); - } + // if ($currentUser && ! $recipients1->contains('id', $currentUser->id)) { + // $recipients1->push($currentUser); + // } - if ($currentUser && ! $recipients->contains('id', $currentUser->id)) { - $recipients->push($currentUser); - } + // if ($currentUser && ! $recipients->contains('id', $currentUser->id)) { + // $recipients->push($currentUser); + // } // $user1 = Filament::auth()->user(); $body = "{$currentUser->name} current rank is #{$rank}"; + // Notification::make() + // ->title('Rank Updated') + // ->body("{$currentUser->name} current rank is #{$rank}") + // ->success() + // ->sendToDatabase($recipients); + + // \Log::info('Notification sent', [ + // 'rank' => $rank, + // 'recipients' => $recipients->pluck('id'), + // ]); + Notification::make() - ->title('Rank Updated') - ->body("{$currentUser->name} current rank is #{$rank}") - ->success() - ->sendToDatabase($recipients); + ->title('Rank Updated') + ->body("{$currentUser->name} current rank is #{$rank}") + ->success() + ->sendToDatabase($users); - \Log::info('Notification sent', [ - 'rank' => $rank, - 'recipients' => $recipients->pluck('id'), - ]); + // foreach ($recipients1 as $user) { + // $user->notify( + // new PushAlertNotification( + // 'Rank Updated', + // $body + // ) + // ); + // } - foreach ($recipients1 as $user) { - $user->notify( - new PushAlertNotification( - 'Rank Updated', - $body - ) - ); + foreach ($users as $user) { + if ($user->pushSubscriptions()->exists()) { + $user->notify( + new PushAlertNotification( + 'Rank Updated', + $body + ) + ); + } }