mirror of
				https://github.com/pelican-dev/panel.git
				synced 2025-11-04 07:46:53 +01:00 
			
		
		
		
	Make sure variables are unique per egg (#902)
* Add unique validation * Also make their name unique * Custom message
This commit is contained in:
		
							parent
							
								
									7f3b1fd758
								
							
						
					
					
						commit
						d1007ad2fe
					
				@ -17,10 +17,12 @@ use Filament\Forms\Components\Textarea;
 | 
			
		||||
use Filament\Forms\Components\TextInput;
 | 
			
		||||
use Filament\Forms\Components\Toggle;
 | 
			
		||||
use Filament\Forms\Form;
 | 
			
		||||
use Filament\Forms\Get;
 | 
			
		||||
use Filament\Forms\Set;
 | 
			
		||||
use Filament\Resources\Pages\CreateRecord;
 | 
			
		||||
use Illuminate\Database\Eloquent\Model;
 | 
			
		||||
use Illuminate\Support\Str;
 | 
			
		||||
use Illuminate\Validation\Rules\Unique;
 | 
			
		||||
 | 
			
		||||
class CreateEgg extends CreateRecord
 | 
			
		||||
{
 | 
			
		||||
@ -172,8 +174,11 @@ class CreateEgg extends CreateRecord
 | 
			
		||||
                                        ->debounce(750)
 | 
			
		||||
                                        ->maxLength(255)
 | 
			
		||||
                                        ->columnSpanFull()
 | 
			
		||||
                                        ->afterStateUpdated(fn (Set $set, $state) => $set('env_variable', str($state)->trim()->snake()->upper()->toString())
 | 
			
		||||
                                        )
 | 
			
		||||
                                        ->afterStateUpdated(fn (Set $set, $state) => $set('env_variable', str($state)->trim()->snake()->upper()->toString()))
 | 
			
		||||
                                        ->unique(modifyRuleUsing: fn (Unique $rule, Get $get) => $rule->where('egg_id', $get('../../id')), ignoreRecord: true)
 | 
			
		||||
                                        ->validationMessages([
 | 
			
		||||
                                            'unique' => 'A variable with this name already exists.',
 | 
			
		||||
                                        ])
 | 
			
		||||
                                        ->required(),
 | 
			
		||||
                                    Textarea::make('description')->columnSpanFull(),
 | 
			
		||||
                                    TextInput::make('env_variable')
 | 
			
		||||
@ -183,6 +188,10 @@ class CreateEgg extends CreateRecord
 | 
			
		||||
                                        ->suffix('}}')
 | 
			
		||||
                                        ->hintIcon('tabler-code')
 | 
			
		||||
                                        ->hintIconTooltip(fn ($state) => "{{{$state}}}")
 | 
			
		||||
                                        ->unique(modifyRuleUsing: fn (Unique $rule, Get $get) => $rule->where('egg_id', $get('../../id')), ignoreRecord: true)
 | 
			
		||||
                                        ->validationMessages([
 | 
			
		||||
                                            'unique' => 'A variable with this name already exists.',
 | 
			
		||||
                                        ])
 | 
			
		||||
                                        ->required(),
 | 
			
		||||
                                    TextInput::make('default_value')->maxLength(255),
 | 
			
		||||
                                    Fieldset::make('User Permissions')
 | 
			
		||||
 | 
			
		||||
@ -22,8 +22,10 @@ use Filament\Forms\Components\Textarea;
 | 
			
		||||
use Filament\Forms\Components\TextInput;
 | 
			
		||||
use Filament\Forms\Components\Toggle;
 | 
			
		||||
use Filament\Forms\Form;
 | 
			
		||||
use Filament\Forms\Get;
 | 
			
		||||
use Filament\Forms\Set;
 | 
			
		||||
use Filament\Resources\Pages\EditRecord;
 | 
			
		||||
use Illuminate\Validation\Rules\Unique;
 | 
			
		||||
 | 
			
		||||
class EditEgg extends EditRecord
 | 
			
		||||
{
 | 
			
		||||
@ -163,8 +165,11 @@ class EditEgg extends EditRecord
 | 
			
		||||
                                        ->debounce(750)
 | 
			
		||||
                                        ->maxLength(255)
 | 
			
		||||
                                        ->columnSpanFull()
 | 
			
		||||
                                        ->afterStateUpdated(fn (Set $set, $state) => $set('env_variable', str($state)->trim()->snake()->upper()->toString())
 | 
			
		||||
                                        )
 | 
			
		||||
                                        ->afterStateUpdated(fn (Set $set, $state) => $set('env_variable', str($state)->trim()->snake()->upper()->toString()))
 | 
			
		||||
                                        ->unique(modifyRuleUsing: fn (Unique $rule, Get $get) => $rule->where('egg_id', $get('../../id')), ignoreRecord: true)
 | 
			
		||||
                                        ->validationMessages([
 | 
			
		||||
                                            'unique' => 'A variable with this name already exists.',
 | 
			
		||||
                                        ])
 | 
			
		||||
                                        ->required(),
 | 
			
		||||
                                    Textarea::make('description')->columnSpanFull(),
 | 
			
		||||
                                    TextInput::make('env_variable')
 | 
			
		||||
@ -174,6 +179,10 @@ class EditEgg extends EditRecord
 | 
			
		||||
                                        ->suffix('}}')
 | 
			
		||||
                                        ->hintIcon('tabler-code')
 | 
			
		||||
                                        ->hintIconTooltip(fn ($state) => "{{{$state}}}")
 | 
			
		||||
                                        ->unique(modifyRuleUsing: fn (Unique $rule, Get $get) => $rule->where('egg_id', $get('../../id')), ignoreRecord: true)
 | 
			
		||||
                                        ->validationMessages([
 | 
			
		||||
                                            'unique' => 'A variable with this name already exists.',
 | 
			
		||||
                                        ])
 | 
			
		||||
                                        ->required(),
 | 
			
		||||
                                    TextInput::make('default_value')->maxLength(255),
 | 
			
		||||
                                    Fieldset::make('User Permissions')
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user