Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Has been cancelled
Gemini PR Review / Gemini PR Review (pull_request) Successful in 20s
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (pull_request) Successful in 12s
Laravel Pint / pint (pull_request) Failing after 5m21s
Laravel Larastan / larastan (pull_request) Failing after 5m34s
85 lines
2.4 KiB
PHP
85 lines
2.4 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Resources\RfqTransporterBidResource\Pages;
|
|
|
|
use App\Filament\Resources\RfqTransporterBidResource;
|
|
use App\Models\RfqTransporterBid;
|
|
use App\Models\User;
|
|
use App\Notifications\PushAlertNotification;
|
|
use Filament\Actions;
|
|
use Filament\Facades\Filament;
|
|
use Filament\Notifications\Notification;
|
|
use Filament\Resources\Pages\EditRecord;
|
|
|
|
class EditRfqTransporterBid extends EditRecord
|
|
{
|
|
protected static string $resource = RfqTransporterBidResource::class;
|
|
|
|
protected function afterSave(): void
|
|
{
|
|
if (! $this->record->wasChanged('total_freight_charge')) {
|
|
return;
|
|
}
|
|
|
|
// dd($this->record);
|
|
|
|
$rank = RfqTransporterBid::where('request_quotation_id', $this->record->request_quotation_id)
|
|
->orderBy('total_freight_charge')
|
|
->pluck('id')
|
|
->search($this->record->id) + 1;
|
|
|
|
$recipients = User::role(['Super Admin', 'Rfq Supervisor', 'TransporterBid Employee'])->get();
|
|
|
|
$recipients1 = User::role(['Super Admin', 'Rfq Supervisor', 'TransporterBid Employee'])->whereHas('pushSubscriptions')->get();
|
|
|
|
dd($recipients1);
|
|
|
|
$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();
|
|
|
|
|
|
$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'),
|
|
]);
|
|
|
|
foreach ($recipients1 as $user) {
|
|
$user->notify(
|
|
new PushAlertNotification(
|
|
'Rank Updated',
|
|
$body
|
|
)
|
|
);
|
|
}
|
|
|
|
|
|
}
|
|
|
|
protected function getHeaderActions(): array
|
|
{
|
|
return [
|
|
Actions\ViewAction::make(),
|
|
Actions\DeleteAction::make(),
|
|
Actions\ForceDeleteAction::make(),
|
|
Actions\RestoreAction::make(),
|
|
];
|
|
}
|
|
}
|