芝麻web文件管理V1.00
编辑当前文件:/home/forge/stage.herta-bht.smartcon-survey.com/app/Filament/Actions/PublishDataAction.php
label('Publish') ->icon('heroicon-o-rocket-launch') ->form(self::modalForm()) ->action(fn ($data) => self::modalAction($data)); } private static function modalForm(): array { return [ Forms\Components\Select::make('country_id') ->label('Country') ->options(Country::pluck('name', 'id')) ->reactive() ->required(), Forms\Components\Select::make('wave') ->options(fn ($get) => DataUpload::getWaves($get('country_id')) ->mapWithKeys(function (DataUpload $dataUpload) { if ($dataUpload->published) { return [-$dataUpload->wave => 'W'.$dataUpload->wave.' (Published)']; } return [$dataUpload->wave => 'W'.$dataUpload->wave]; }) ) ->visible(fn ($get) => $get('country_id')) ->disableOptionWhen(fn ($value): bool => $value < 0) ->required(), ]; } private static function modalAction(array $data): void { if ($data['country_id'] === null || $data['wave'] === null) { Notification::make('error') ->title('Error')->body('You must select a country and wave') ->danger()->send(); return; } $dataUpload = DataUpload::where('country_id', $data['country_id']) ->where('wave', $data['wave']) ->first(); if ($dataUpload === null) { Notification::make('error') ->title('Error')->body('No data found for the selected country and wave') ->danger()->send(); return; } $dataUpload->update(['published' => true]); Cache::flush(); Notification::make('success') ->title('The interviews have been published successfully') ->body("The {$dataUpload->country->name} interviews wave $dataUpload->wave published") ->success()->duration(6000)->send(); } }