From 00f96f9770e728c40f65fb397594386f8cb9f63a Mon Sep 17 00:00:00 2001 From: Elsevar Date: Thu, 22 Feb 2024 08:10:11 +0000 Subject: [PATCH] Update AnnouncementResource.php --- src/Resources/AnnouncementResource.php | 63 +++++++++++++++----------- 1 file changed, 36 insertions(+), 27 deletions(-) diff --git a/src/Resources/AnnouncementResource.php b/src/Resources/AnnouncementResource.php index 2c404f1..e6cc187 100644 --- a/src/Resources/AnnouncementResource.php +++ b/src/Resources/AnnouncementResource.php @@ -4,9 +4,12 @@ use App\Models\User; use Filament\Forms\Components\ColorPicker; +use Filament\Forms\Components\Section; use Filament\Forms\Components\Select; use Filament\Forms\Components\Textarea; use Filament\Forms\Components\TextInput; +use Filament\Forms\Components\Checkbox; +use Filament\Forms\Components\Toggle; use Filament\Forms\Form; use Filament\Forms\Get; use Filament\Resources\Resource; @@ -29,34 +32,40 @@ public static function form(Form $form): Form { return $form ->schema([ - TextInput::make('name') - ->minLength(5) - ->required(), - TextInput::make('title') - ->minLength(5) - ->required(), - Textarea::make('body') - ->minLength(20) - ->required(), - IconPicker::make('icon'), - Select::make('color') - ->options([ - ...collect(FilamentColor::getColors())->map(fn ($value, $key) => ucfirst($key))->toArray(), - 'custom' => 'Custom', - ]) - ->live(), - ColorPicker::make('custom_color') - ->hidden(fn (Get $get) => $get('color') != 'custom') - ->requiredIf('color', 'custom') - ->rgb(), + Section::make() + ->schema([ + TextInput::make('name') + ->minLength(5) + ->required(), + TextInput::make('title') + ->minLength(5) + ->required(), + Textarea::make('body') + ->minLength(20) + ->required(), + IconPicker::make('icon'), + Select::make('color') + ->options([ + ...collect(FilamentColor::getColors())->map(fn($value, $key) => ucfirst($key))->toArray(), + 'custom' => 'Custom', + ]) + ->live(), + ColorPicker::make('custom_color') + ->hidden(fn(Get $get) => $get('color') != 'custom') + ->requiredIf('color', 'custom') + ->rgb(), - Select::make('users') - ->options([ - 'all' => 'all', - ...User::all()->pluck('name', 'id'), - ]) - ->multiple() - ->required(), + Select::make('users') + ->options(User::pluck('name', 'id')->toArray()) + ->hidden(fn(Get $get) => $get('all_users')) + ->multiple() + ->required(), + ])->columns(2), + + Toggle::make('all_users') + ->live() + ->label('All users') + ->default(false), ]); }