record->wasChanged('total_freight_charge')) { return; } $rank = RfqTransporterBid::where('request_quotation_id', $this->record->request_quotation_id) ->orderBy('total_freight_charge') ->pluck('id') ->search($this->record->id) + 1; $requestQuotation = RequestQuotation::findOrFail( $this->record->request_quotation_id ); $spotRateId = $requestQuotation->spot_rate_transport_master_id; $spotRate = SpotRateTransportMaster::findOrFail($spotRateId); $userNames = $spotRate->user_name; 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 && ! $recipients->contains('id', $currentUser->id)) { // $recipients->push($currentUser); // } // $user1 = Filament::auth()->user(); $rfqNumber = $this->record->requestQuotation->rfq_number; $body = "{$currentUser->name} has updated the bid for RFQ No '{$rfqNumber}'. The 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} has updated the bid for RFQ No '{$rfqNumber}'. The current rank is #{$rank}.") ->success() ->sendToDatabase($users); // 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 ) ); } } } protected function getHeaderActions(): array { return [ Actions\ViewAction::make(), Actions\DeleteAction::make(), Actions\ForceDeleteAction::make(), Actions\RestoreAction::make(), ]; } }