Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

NotifiesOnDelete.php 1.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. namespace App\Traits;
  3. use Filament\Notifications\Notification;
  4. use Illuminate\Database\Eloquent\Model;
  5. use Illuminate\Support\Collection;
  6. trait NotifiesOnDelete
  7. {
  8. public static function notifyBeforeDelete(Model $record, string $reason): void
  9. {
  10. $reason = translate($reason);
  11. Notification::make()
  12. ->danger()
  13. ->title(translate('Action Denied'))
  14. ->body(translate(':Name cannot be deleted because it is :reason. Please update settings before deletion.', [
  15. 'Name' => $record->getAttribute('name'),
  16. 'reason' => $reason,
  17. ]))
  18. ->persistent()
  19. ->send();
  20. }
  21. public static function notifyBeforeDeleteMultiple(Collection $records, string $reason): void
  22. {
  23. $reason = translate($reason);
  24. $namesList = implode('<br>', array_map(static function ($record) {
  25. return '&bull; ' . $record->getAttribute('name');
  26. }, $records->all()));
  27. $message = translate('The following items cannot be deleted because they are :reason. Please update settings before deletion.', compact('reason')) . '<br><br>';
  28. $message .= $namesList;
  29. Notification::make()
  30. ->danger()
  31. ->title(translate('Action Denied'))
  32. ->body($message)
  33. ->persistent()
  34. ->send();
  35. }
  36. }