Loading foreign key value while update for productionLineStop
This commit is contained in:
@@ -8,6 +8,7 @@ use App\Filament\Resources\ProductionLineStopResource\RelationManagers;
|
|||||||
use App\Models\ProductionLineStop;
|
use App\Models\ProductionLineStop;
|
||||||
use Filament\Forms;
|
use Filament\Forms;
|
||||||
use Filament\Forms\Form;
|
use Filament\Forms\Form;
|
||||||
|
use Filament\Forms\Get;
|
||||||
use Filament\Resources\Resource;
|
use Filament\Resources\Resource;
|
||||||
use Filament\Tables;
|
use Filament\Tables;
|
||||||
use Filament\Tables\Actions\ImportAction;
|
use Filament\Tables\Actions\ImportAction;
|
||||||
@@ -39,6 +40,7 @@ class ProductionLineStopResource extends Resource
|
|||||||
->required()
|
->required()
|
||||||
// ->nullable()
|
// ->nullable()
|
||||||
->reactive()
|
->reactive()
|
||||||
|
->disabled(fn (Get $get) => !empty($get('id')))
|
||||||
// ->afterStateUpdated(fn ($set) => $set('block_name', null))
|
// ->afterStateUpdated(fn ($set) => $set('block_name', null))
|
||||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||||
$plantId = $get('plant_id');
|
$plantId = $get('plant_id');
|
||||||
@@ -71,10 +73,31 @@ class ProductionLineStopResource extends Resource
|
|||||||
->toArray();
|
->toArray();
|
||||||
})
|
})
|
||||||
->reactive()
|
->reactive()
|
||||||
|
// ->default(function (callable $get, callable $set) {
|
||||||
|
// if ($get('id')) {
|
||||||
|
// $getShift = ProductionLineStop::where('id', $get('id'))->first();
|
||||||
|
// $getBlock = \App\Models\Shift::where('id', $getShift->shift_id)->first();
|
||||||
|
// // dd($getBlock->block_id);
|
||||||
|
// $set('block_name', $getBlock->block_id);
|
||||||
|
// }
|
||||||
|
// // return null; // Return null if no default value should be set
|
||||||
|
// })
|
||||||
// ->afterStateUpdated(fn ($set) => $set('shift_id', null))
|
// ->afterStateUpdated(fn ($set) => $set('shift_id', null))
|
||||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||||
|
if($get('id'))
|
||||||
|
{
|
||||||
|
$getShift = ProductionLineStop::where('id', $get('id'))->first();
|
||||||
|
$getBlock = \App\Models\Shift::where('id', $getShift->shift_id)->first();
|
||||||
|
if($getBlock->block_id)
|
||||||
|
{
|
||||||
|
$set('block_name', $getBlock->block_id);
|
||||||
|
$set('plsBlockError', null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$blockId = $get('block_name');
|
$blockId = $get('block_name');
|
||||||
$set('shift_id', null);
|
$set('shift_id', null);
|
||||||
|
|
||||||
if (!$blockId) {
|
if (!$blockId) {
|
||||||
$set('plsBlockError', 'Please select a block first.');
|
$set('plsBlockError', 'Please select a block first.');
|
||||||
return;
|
return;
|
||||||
@@ -102,7 +125,6 @@ class ProductionLineStopResource extends Resource
|
|||||||
if (!$get('plant_id') || !$get('block_name')) {
|
if (!$get('plant_id') || !$get('block_name')) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
// // Get the block ID based on plant_id and block_name
|
// // Get the block ID based on plant_id and block_name
|
||||||
// $block = \App\Models\Block::where('plant_id', $get('plant_id'))
|
// $block = \App\Models\Block::where('plant_id', $get('plant_id'))
|
||||||
// ->where('name', $get('block_name'))
|
// ->where('name', $get('block_name'))
|
||||||
@@ -123,8 +145,19 @@ class ProductionLineStopResource extends Resource
|
|||||||
->reactive()
|
->reactive()
|
||||||
// ->afterStateUpdated(fn ($set) => $set('line_id', null))
|
// ->afterStateUpdated(fn ($set) => $set('line_id', null))
|
||||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||||
|
if($get('id'))
|
||||||
|
{
|
||||||
|
$getShift = ProductionLineStop::where('id', $get('id'))->first();
|
||||||
|
if($getShift->shift_id)
|
||||||
|
{
|
||||||
|
$set('shift_id', $getShift->shift_id);
|
||||||
|
$set('plsShiftError', null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$shiftId = $get('shift_id');
|
$shiftId = $get('shift_id');
|
||||||
$set('line_id', null);
|
$set('line_id', null);
|
||||||
|
|
||||||
if (!$shiftId) {
|
if (!$shiftId) {
|
||||||
$set('plsShiftError', 'Please select a shift first.');
|
$set('plsShiftError', 'Please select a shift first.');
|
||||||
return;
|
return;
|
||||||
@@ -159,7 +192,18 @@ class ProductionLineStopResource extends Resource
|
|||||||
})
|
})
|
||||||
->reactive()
|
->reactive()
|
||||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||||
|
if($get('id'))
|
||||||
|
{
|
||||||
|
$getShift = ProductionLineStop::where('id', $get('id'))->first();
|
||||||
|
if($getShift->line_id)
|
||||||
|
{
|
||||||
|
$set('line_id', $getShift->line_id);
|
||||||
|
$set('plsLineError', null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$lineId = $get('line_id');
|
$lineId = $get('line_id');
|
||||||
|
|
||||||
if (!$lineId) {
|
if (!$lineId) {
|
||||||
$set('plsLineError', 'Please select a line first.');
|
$set('plsLineError', 'Please select a line first.');
|
||||||
return;
|
return;
|
||||||
@@ -243,6 +287,9 @@ class ProductionLineStopResource extends Resource
|
|||||||
// ->dehydrated(false)
|
// ->dehydrated(false)
|
||||||
->readOnly(true)
|
->readOnly(true)
|
||||||
->numeric(),
|
->numeric(),
|
||||||
|
Forms\Components\TextInput::make('id')
|
||||||
|
->hidden()
|
||||||
|
->readOnly(),
|
||||||
])
|
])
|
||||||
->columns(2),
|
->columns(2),
|
||||||
]);
|
]);
|
||||||
|
|||||||
Reference in New Issue
Block a user