Files
qds/app/Filament/Resources/RfqTransporterBidResource/Pages/CreateRfqTransporterBid.php
dhanabalan a34322c87a
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 10s
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (pull_request) Successful in 10s
Gemini PR Review / Gemini PR Review (pull_request) Successful in 13s
Laravel Larastan / larastan (pull_request) Failing after 2m27s
Laravel Pint / pint (pull_request) Failing after 2m42s
Added after craete method in transporter bid
2026-01-24 15:06:54 +05:30

66 lines
1.9 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\CreateRecord;
class CreateRfqTransporterBid extends CreateRecord
{
protected static string $resource = RfqTransporterBidResource::class;
protected function afterCreate(): void
{
$record = $this->record;
// Calculate rank based on total_freight_charge
$rank = RfqTransporterBid::where('request_quotation_id', $record->request_quotation_id)
->orderBy('total_freight_charge')
->pluck('id')
->search($record->id) + 1;
$currentUser = Filament::auth()->user();
// Get recipients
$recipients = User::whereHas('roles', function ($q) {
$q->whereIn('name', ['Super Admin', 'Rfq Supervisor'])
->where('guard_name', 'web');
})->get();
// Exclude creator
$recipients = $recipients->where('id', '!=', $currentUser->id);
$body = "{$currentUser->name} added a new bid. Current rank is #{$rank}";
// Filament DB notification
Notification::make()
->title('New Bid Added')
->body($body)
->success()
->sendToDatabase($recipients);
// Push notification
foreach ($recipients as $user) {
$user->notify(
new PushAlertNotification(
'New Bid Added',
$body
)
);
}
\Log::info('Create bid notification sent', [
'bid_id' => $record->id,
'rank' => $rank,
'recipients' => $recipients->pluck('id'),
]);
}
}