Loading foreign key value while update

This commit is contained in:
dhanabalan
2025-04-01 16:16:37 +05:30
parent 6160d91357
commit a8b34fe1f3
6 changed files with 207 additions and 212 deletions

View File

@@ -7,6 +7,7 @@ use App\Filament\Resources\BlockResource\Pages;
use App\Models\Block;
use Filament\Forms;
use Filament\Forms\Form;
use Filament\Forms\Get;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Actions\ImportAction;
@@ -58,6 +59,7 @@ class BlockResource extends Resource
// ->unique(ignoreRecord: true)
->required()
->reactive()
->disabled(fn (Get $get) => !empty($get('id')))
->afterStateUpdated(function ($state, callable $set, callable $get) {
$nameId = $get('plant_id');
// Ensure `linestop_id` is not cleared
@@ -75,6 +77,9 @@ class BlockResource extends Resource
])
->hint(fn ($get) => $get('bPlantError') ? $get('bPlantError') : null)
->hintColor('danger'),
Forms\Components\TextInput::make('id')
->hidden()
->readOnly(),
])
->columns(2),
]);

View File

@@ -8,6 +8,7 @@ use App\Filament\Resources\ItemResource\Pages;
use App\Models\Item;
use Filament\Forms;
use Filament\Forms\Form;
use Filament\Forms\Get;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Actions\ExportAction;
@@ -38,6 +39,7 @@ class ItemResource extends Resource
->required()
// ->nullable(),
->reactive()
->disabled(fn (Get $get) => !empty($get('id')))
// ->afterStateUpdated(fn ($set) => $set('block_id', null) & $set('name', null) & $set('start_time', null) & $set('duration', null) & $set('end_time', null))
->afterStateUpdated(function ($state, callable $set, callable $get) {
$plantId = $get('plant_id');
@@ -64,6 +66,7 @@ class ItemResource extends Resource
->minLength(6)
// ->autocapitalize('characters')
->reactive()
->disabled(fn (Get $get) => !empty($get('id')))
->afterStateUpdated(function ($state, callable $set, callable $get) {
$code = $get('code');
// Ensure `linestop_id` is not cleared
@@ -123,6 +126,9 @@ class ItemResource extends Resource
->required()
->placeholder('Scan the valid description'),
// ->columnSpanFull(),
Forms\Components\TextInput::make('id')
->hidden()
->readOnly(),
])
->columns(2),
]);

View File

@@ -8,6 +8,7 @@ use App\Filament\Resources\LineResource\RelationManagers;
use App\Models\Line;
use Filament\Forms;
use Filament\Forms\Form;
use Filament\Forms\Get;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Actions\ImportAction;
@@ -37,6 +38,7 @@ class LineResource extends Resource
->required()
// ->nullable(),
->reactive()
->disabled(fn (Get $get) => !empty($get('id')))
// ->afterStateUpdated(fn ($set) => $set('block_id', null) & $set('name', null) & $set('start_time', null) & $set('duration', null) & $set('end_time', null))
->afterStateUpdated(function ($state, callable $set, callable $get) {
$plantId = $get('plant_id');
@@ -124,6 +126,9 @@ class LineResource extends Resource
])
->hint(fn ($get) => $get('lTypeError') ? $get('lTypeError') : null)
->hintColor('danger'),
Forms\Components\TextInput::make('id')
->hidden()
->readOnly(),
])
->columns(2),
]);

View File

@@ -8,6 +8,7 @@ use App\Models\Plant;
use Filament\Forms;
use Filament\Forms\Components\Section;
use Filament\Forms\Form;
use Filament\Forms\Get;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Actions\ImportAction;
@@ -69,6 +70,7 @@ class PlantResource extends Resource
->relationship('company', 'name')
->required()
->reactive()
->disabled(fn (Get $get) => !empty($get('id')))
->afterStateUpdated(function ($state, callable $set, callable $get) {
$companyId = $get('company_id');
// Ensure `linestop_id` is not cleared
@@ -132,6 +134,9 @@ class PlantResource extends Resource
])
->hint(fn ($get) => $get('pAddressError') ? $get('pAddressError') : null)
->hintColor('danger'),
Forms\Components\TextInput::make('id')
->hidden()
->readOnly(),
])
->columns(2),
]);

View File

@@ -8,6 +8,7 @@ use App\Models\Shift;
use Carbon\Carbon;
use Filament\Forms;
use Filament\Forms\Form;
use Filament\Forms\Get;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Actions\ImportAction;
@@ -37,6 +38,7 @@ class ShiftResource extends Resource
->required()
// ->nullable()
->reactive()
->disabled(fn (Get $get) => !empty($get('id')))
// ->afterStateUpdated(fn ($set) => $set('block_id', null) & $set('name', null) & $set('start_time', null) & $set('duration', null) & $set('end_time', null))
->afterStateUpdated(function ($state, callable $set, callable $get) {
$plantId = $get('plant_id');
@@ -60,6 +62,7 @@ class ShiftResource extends Resource
->required()
// ->nullable()
->reactive()
->disabled(fn (Get $get) => !empty($get('id')))
// ->options(fn (callable $get) =>
// \App\Models\Block::where('plant_id', $get('plant_id'))
// ->pluck('name', 'id')
@@ -203,6 +206,9 @@ class ShiftResource extends Resource
])
->hint(fn ($get) => $get('sEndTimeError') ? $get('sEndTimeError') : null)
->hintColor('danger'),
Forms\Components\TextInput::make('id')
->hidden()
->readOnly(),
])
->columns(2),
]);

View File

@@ -32,7 +32,7 @@ class StickerMasterResource extends Resource
->relationship('plant', 'name')
->reactive()
->nullable()
->disabled(fn (Get $get) => !empty($get('id')))
->disabled(fn (Get $get) => !empty($get('id'))) //disable in edit if user try to change
->afterStateUpdated(fn (callable $set) =>
$set('item_id', null) & $set('item_description', null)
)
@@ -56,8 +56,8 @@ class StickerMasterResource extends Resource
->disabled(fn (Get $get) => !empty($get('id')))
->live(debounce: 500) // Enable live updates
->afterStateUpdated(function ($state, callable $set, callable $get) {
$plantId = $get('plant_id'); // Get selected plant_id
$itemId = $get('item_id'); // Get entered item_id
$plantId = $get('plant_id');
$itemId = $get('item_id');
// Ensure `item_id` is not cleared
if (!$plantId || !$itemId) {
@@ -77,13 +77,6 @@ class StickerMasterResource extends Resource
}
}),
// ->validationAttribute('Item Code')
// ->rule('required')
// ->extraAttributes(fn ($get) => [
// 'class' => $get('validationError') ? 'border-red-500' : '',
// ])
// ->hint(fn ($get) => $get('validationError') ? $get('validationError') : null)
// ->hintColor('danger'), // Show error in red under the input field
Forms\Components\TextInput::make('item_description')
->label('Description')
@@ -91,8 +84,6 @@ class StickerMasterResource extends Resource
->reactive()
->readOnly(true),
//Forms\Components\Textarea::make('serial_number_motor'),
Forms\Components\TextInput::make('part_validation1')
->nullable(),
@@ -112,77 +103,54 @@ class StickerMasterResource extends Resource
->nullable()
->dehydrateStateUsing(fn ($state) => $state ? $state : null),
//Forms\Components\Textarea::make('serial_number_pump')
Forms\Components\Checkbox::make('serial_number_pump')
->nullable()
->dehydrateStateUsing(fn ($state) => $state ? $state : null),
//Forms\Components\TextInput::make('serial_number_pumpset'),
Forms\Components\Checkbox::make('serial_number_pumpset')
->nullable()
->dehydrateStateUsing(fn ($state) => $state ? $state : null),
//Forms\Components\TextInput::make('pack_slip_motor'),
Forms\Components\Checkbox::make('pack_slip_motor')
->nullable()
->dehydrateStateUsing(fn ($state) => $state ? $state : null),
//Forms\Components\TextInput::make('pack_slip_pump'),
Forms\Components\Checkbox::make('pack_slip_pump')
->nullable()
->dehydrateStateUsing(fn ($state) => $state ? $state : null),
//Forms\Components\TextInput::make('pack_slip_pumpset'),
Forms\Components\Checkbox::make('pack_slip_pumpset')
->nullable()
->dehydrateStateUsing(fn ($state) => $state ? $state : null),
//Forms\Components\TextInput::make('name_plate_motor'),
Forms\Components\Checkbox::make('name_plate_motor')
->nullable()
->dehydrateStateUsing(fn ($state) => $state ? $state : null),
//Forms\Components\TextInput::make('name_plate_pump'),
Forms\Components\Checkbox::make('name_plate_pump')
->nullable()
->dehydrateStateUsing(fn ($state) => $state ? $state : null),
//Forms\Components\TextInput::make('name_plate_pumpset'),
Forms\Components\Checkbox::make('name_plate_pumpset')
->nullable()
->dehydrateStateUsing(fn ($state) => $state ? $state : null),
//Forms\Components\TextInput::make('tube_sticker_motor'),
Forms\Components\Checkbox::make('tube_sticker_motor')
->nullable()
->dehydrateStateUsing(fn ($state) => $state ? $state : null),
//Forms\Components\TextInput::make('tube_sticker_pump'),
Forms\Components\Checkbox::make('tube_sticker_pump')
->nullable()
->dehydrateStateUsing(fn ($state) => $state ? $state : null),
//Forms\Components\TextInput::make('tube_sticker_pumpset'),
Forms\Components\Checkbox::make('tube_sticker_pumpset')
->nullable()
->dehydrateStateUsing(fn ($state) => $state ? $state : null),
//Forms\Components\TextInput::make('warranty_card'),
->dehydrateStateUsing(fn ($state) => $state ? $state : null), //to pass null value
Forms\Components\Checkbox::make('warranty_card')
->nullable()
->dehydrateStateUsing(fn ($state) => $state ? $state : null),
Forms\Components\TextInput::make('id')
->hidden()
->readOnly(),