🆙 More fixes 🆙

This commit is contained in:
Remco
2026-01-20 17:48:16 +01:00
parent 5b3645abba
commit 9a8fa8b1ff
7 changed files with 55 additions and 42 deletions
@@ -2,10 +2,9 @@
namespace App\Filament\Resources\User\Users\Pages;
use App\Enums\NotificationType;
use App\Filament\Resources\User\Users\UserResource;
use App\Models\User;
use App\Models\User\UserNotification;
use Illuminate\Support\Facades\DB;
use Filament\Actions\Action;
use Filament\Actions\CreateAction;
use Filament\Forms\Components\Select;
@@ -49,27 +48,32 @@ class ListUsers extends ListRecords
->default(false),
])
->action(function (array $data): void {
$notifications = collect();
$allUsersId = collect($data['users'])->values();
$senderId = $data['as_staff'] ? null : auth()->id();
$allUsersId = collect($data['users'] ?? [])->values();
$senderId = !empty($data['as_staff']) ? null : auth()->id();
if ($allUsersId->isEmpty()) {
$allUsersId = User::select('id')->get()->pluck('id');
}
$allUsersId->each(function ($userId) use ($senderId, $data, $notifications): void {
$notifications->push([
$rows = [];
$message = is_string($data['message'] ?? null) ? $data['message'] : '';
$url = is_string($data['url'] ?? null) ? $data['url'] : null;
$now = now();
$type = 'housekeeping_custom_message';
$allUsersId->each(function ($userId) use ($senderId, $message, $url, $now, $type, &$rows): void {
$rows[] = [
'sender_id' => $senderId,
'recipient_id' => $userId,
'type' => NotificationType::HousekeepingCustomMessage,
'message' => $data['message'],
'url' => $data['url'] ?? null,
'created_at' => now(),
'updated_at' => now(),
]);
'recipient_id' => is_numeric($userId) ? (int) $userId : null,
'type' => $type,
'message' => $message,
'url' => $url,
'created_at' => $now,
'updated_at' => $now,
];
});
UserNotification::insert($notifications->toArray());
if (! empty($rows)) {
DB::table('user_notifications')->insert($rows);
}
Notification::make()
->body(__('Notification sent successfully.'))