Added combined unique and default value

This commit is contained in:
dhanabalan
2025-04-08 09:19:53 +05:30
parent f066794bca
commit 4ad7a4e524
3 changed files with 96 additions and 42 deletions

View File

@@ -48,6 +48,9 @@ class ProductionLineStopResource extends Resource
->required()
// ->nullable()
->reactive()
->default(function () {
return optional(ProductionLineStop::latest()->first())->plant_id;
})
->disabled(fn (Get $get) => !empty($get('id')))
// ->afterStateUpdated(fn ($set) => $set('block_name', null))
->afterStateUpdated(function ($state, callable $set, callable $get) {
@@ -82,23 +85,18 @@ class ProductionLineStopResource extends Resource
->toArray();
})
->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
// })
->default(function () {
$latestShiftId = optional(ProductionLineStop::latest()->first())->shift_id;
return optional(Shift::where('id', $latestShiftId)->first())->block_id;
})
// ->afterStateUpdated(fn ($set) => $set('shift_id', null))
->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();
$getBlock = Shift::where('id', $getShift->shift_id)->first();
if($getBlock->block_id)
// $getBlock = \App\Models\Shift::where('id', $getShift->shift_id)->first();
$getBlock = Shift::where('id', $getShift->shift_id)->first();
if($getBlock->block_id)
{
$set('block_name', $getBlock->block_id);
$set('plsBlockError', null);
@@ -137,6 +135,9 @@ class ProductionLineStopResource extends Resource
->toArray();
})
->reactive()
->default(function () {
return optional(ProductionLineStop::latest()->first())->shift_id;
})
// ->afterStateUpdated(fn ($set) => $set('line_id', null))
->afterStateUpdated(function ($state, callable $set, callable $get) {
if($get('id'))
@@ -181,6 +182,9 @@ class ProductionLineStopResource extends Resource
->toArray();
})
->reactive()
->default(function () {
return optional(ProductionLineStop::latest()->first())->line_id;
})
->afterStateUpdated(function ($state, callable $set, callable $get) {
if($get('id'))
{
@@ -481,7 +485,8 @@ class ProductionLineStopResource extends Resource
])
->headerActions([
ImportAction::make()
->importer(ProductionLineStopImporter::class),
->importer(ProductionLineStopImporter::class)
->maxRows(100000),
]);
}