Guest User

Untitled

a guest
Feb 22nd, 2026
18
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.85 KB | None | 0 0
  1. <?php
  2.  
  3. namespace App\Filament\Support\Resources\Core\SurfPlayers\Pages\Actions;
  4.  
  5. use App\Models\Core\Punishment\Utils\PunishmentTemplate;
  6. use App\Models\Core\SurfPlayer;
  7. use Filament\Actions\Action;
  8. use Filament\Forms\Components\Hidden;
  9. use Filament\Forms\Components\TextInput;
  10. use Filament\Schemas\Components\Actions;
  11. use Illuminate\Support\HtmlString;
  12. use Livewire\Livewire;
  13.  
  14. class PunishAction extends Action
  15. {
  16.     public static function getDefaultName(): ?string
  17.     {
  18.         return "punish";
  19.     }
  20.  
  21.     private static array $permissions = [
  22.         "punish_players",
  23.     ];
  24.  
  25.     private static function checkPermission(): bool
  26.     {
  27.         $authUser = auth()->user();
  28.         return $authUser && collect(self::$permissions)->every(function ($permission) use ($authUser) {
  29.                 return $authUser->can($permission);
  30.             });
  31.     }
  32.  
  33.     protected function setUp(): void
  34.     {
  35.         parent::setUp();
  36.  
  37.         $this->label("Punish");
  38.         $this->icon("fas-gavel");
  39.         $this->color("danger");
  40.  
  41.         $this->hidden(fn() => !self::checkPermission());
  42.         $this->disabled(fn() => !self::checkPermission());
  43.  
  44.         $this->schema([
  45.             Hidden::make("punishment_template")
  46.                 ->required()
  47.                 ->live()
  48.                 ->reactive()
  49.                 ->extraAttributes([
  50.                     "x-on:template-selected.window" => '$state = $event.detail.templateId'
  51.                 ])
  52.                 ->afterStateUpdated(function ($state, callable $set) {
  53.                     $template = PunishmentTemplate::find($state);
  54.  
  55.                     if ($template) {
  56.                         $set("reason", $template->reason);
  57.                     }
  58.                 }),
  59.  
  60.             Actions::make([
  61.                 Action::make("select_template")
  62.                     ->label("Vorlage auswählen")
  63.                     ->modalHeading("Bestrafungsvorlage auswählen")
  64.                     ->modalSubmitAction(false)
  65.                     ->modalCancelActionLabel("Abbrechen")
  66.                     ->modalContent(fn($action) => new HtmlString(Livewire::mount("punishment.template-table")))
  67.             ]),
  68.  
  69.             TextInput::make("template_preview")
  70.                 ->label("Vorschau")
  71.                 ->live()
  72.                 ->reactive()
  73.                 ->readOnly()
  74.                 ->formatStateUsing(function (callable $get) {
  75.                     $id = $get("punishment_template");
  76.                     if (!$id) return "Keine Vorlage ausgewählt.";
  77.  
  78.                     $template = PunishmentTemplate::find($get("punishment_template"));
  79.                     if (!$template) return "Keine Vorlage ausgewählt.";
  80.  
  81.                     return $template->format();
  82.                 })
  83.         ]);
  84.  
  85.         $this->action(function (SurfPlayer $record, array $data): void {
  86.  
  87.         });
  88.     }
  89. }
Advertisement
Add Comment
Please, Sign In to add comment