Updated alignment on resource
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 11s

This commit is contained in:
dhanabalan
2026-01-14 09:06:45 +05:30
parent 13912de584
commit a0a10cb668

View File

@@ -5,7 +5,6 @@ namespace App\Filament\Resources;
use App\Filament\Exports\MachineExporter; use App\Filament\Exports\MachineExporter;
use App\Filament\Imports\MachineImporter; use App\Filament\Imports\MachineImporter;
use App\Filament\Resources\MachineResource\Pages; use App\Filament\Resources\MachineResource\Pages;
use App\Filament\Resources\MachineResource\RelationManagers;
use App\Models\Line; use App\Models\Line;
use App\Models\Machine; use App\Models\Machine;
use App\Models\Plant; use App\Models\Plant;
@@ -16,11 +15,11 @@ use Filament\Forms\Form;
use Filament\Forms\Get; use Filament\Forms\Get;
use Filament\Resources\Resource; use Filament\Resources\Resource;
use Filament\Tables; use Filament\Tables;
use Filament\Tables\Actions\ExportAction;
use Filament\Tables\Actions\ImportAction;
use Filament\Tables\Table; use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope; use Illuminate\Database\Eloquent\SoftDeletingScope;
use Filament\Tables\Actions\ImportAction;
use Filament\Tables\Actions\ExportAction;
use Illuminate\Validation\Rule; use Illuminate\Validation\Rule;
use Str; use Str;
@@ -45,22 +44,22 @@ class MachineResource extends Resource
->reactive() ->reactive()
->options(function (callable $get) { ->options(function (callable $get) {
$userHas = Filament::auth()->user()->plant_id; $userHas = Filament::auth()->user()->plant_id;
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray(); return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray();
}) })
->default(function () { ->default(function () {
return optional(Machine::latest()->first())->plant_id; return optional(Machine::latest()->first())->plant_id;
}) })
->disabled(fn (Get $get) => !empty($get('id'))) ->disabled(fn (Get $get) => ! empty($get('id')))
->afterStateUpdated(function ($state, callable $set, callable $get) { ->afterStateUpdated(function ($state, callable $set, callable $get) {
$plantId = $get('plant_id'); $plantId = $get('plant_id');
if (!$plantId) { if (! $plantId) {
$set('mPlantError', 'Please select a plant first.'); $set('mPlantError', 'Please select a plant first.');
$set('line_id', null); $set('line_id', null);
$set('work_group_master_id', null); $set('work_group_master_id', null);
return; return;
} } else {
else
{
$set('mPlantError', null); $set('mPlantError', null);
} }
}) })
@@ -75,7 +74,7 @@ class MachineResource extends Resource
->required() ->required()
->reactive() ->reactive()
->options(function (callable $get) { ->options(function (callable $get) {
if (!$get('plant_id')) { if (! $get('plant_id')) {
return []; return [];
} }
@@ -84,16 +83,15 @@ class MachineResource extends Resource
->default(function () { ->default(function () {
return optional(Machine::latest()->first())->line_id; return optional(Machine::latest()->first())->line_id;
}) })
->disabled(fn (Get $get) => !empty($get('id'))) ->disabled(fn (Get $get) => ! empty($get('id')))
->afterStateUpdated(function ($state, callable $set, callable $get) { ->afterStateUpdated(function ($state, callable $set, callable $get) {
$lineId = $get('line_id'); $lineId = $get('line_id');
if (!$lineId) { if (! $lineId) {
$set('mLineError', 'Please select a line first.'); $set('mLineError', 'Please select a line first.');
$set('work_group_master_id', null); $set('work_group_master_id', null);
return; return;
} } else {
else
{
// $grpWrkCnr = Line::find($lineId)->group_work_center; // $grpWrkCnr = Line::find($lineId)->group_work_center;
// if (!$grpWrkCnr || Str::length($grpWrkCnr) < 1) // if (!$grpWrkCnr || Str::length($grpWrkCnr) < 1)
// { // {
@@ -115,7 +113,7 @@ class MachineResource extends Resource
->required() ->required()
->reactive() ->reactive()
->options(function (callable $get) { ->options(function (callable $get) {
if (!$get('plant_id') || !$get('line_id')) { if (! $get('plant_id') || ! $get('line_id')) {
return []; return [];
} }
@@ -123,7 +121,7 @@ class MachineResource extends Resource
$workGroupIds = []; $workGroupIds = [];
for ($i = 1; $i <= $line->no_of_operation; $i++) { for ($i = 1; $i <= $line->no_of_operation; $i++) {
$column = "work_group{$i}_id"; $column = "work_group{$i}_id";
if (!empty($line->$column)) { if (! empty($line->$column)) {
$workGroupIds[] = $line->$column; $workGroupIds[] = $line->$column;
} }
} }
@@ -133,15 +131,14 @@ class MachineResource extends Resource
->default(function () { ->default(function () {
return optional(Machine::latest()->first())->work_group_master_id; return optional(Machine::latest()->first())->work_group_master_id;
}) })
->disabled(fn (Get $get) => !empty($get('id'))) ->disabled(fn (Get $get) => ! empty($get('id')))
->afterStateUpdated(function ($state, callable $set, callable $get) { ->afterStateUpdated(function ($state, callable $set, callable $get) {
$lineId = $get('line_id'); $lineId = $get('line_id');
if (!$lineId) { if (! $lineId) {
$set('mGroupWorkError', 'Please select a line first.'); $set('mGroupWorkError', 'Please select a line first.');
return; return;
} } else {
else
{
// $grpWrkCnr = Line::find($lineId)->group_work_center; // $grpWrkCnr = Line::find($lineId)->group_work_center;
// if (!$grpWrkCnr || Str::length($grpWrkCnr) < 1) // if (!$grpWrkCnr || Str::length($grpWrkCnr) < 1)
// { // {
@@ -164,7 +161,7 @@ class MachineResource extends Resource
->required() ->required()
->rule(function (callable $get) { ->rule(function (callable $get) {
return Rule::unique('machines', 'name') return Rule::unique('machines', 'name')
//->where('line_id', $get('line_id')) // ->where('line_id', $get('line_id'))
->where('plant_id', $get('plant_id')) ->where('plant_id', $get('plant_id'))
->ignore($get('id')); // Ignore current record during updates ->ignore($get('id')); // Ignore current record during updates
}), }),
@@ -194,6 +191,7 @@ class MachineResource extends Resource
$paginator = $livewire->getTableRecords(); $paginator = $livewire->getTableRecords();
$perPage = method_exists($paginator, 'perPage') ? $paginator->perPage() : 10; $perPage = method_exists($paginator, 'perPage') ? $paginator->perPage() : 10;
$currentPage = method_exists($paginator, 'currentPage') ? $paginator->currentPage() : 1; $currentPage = method_exists($paginator, 'currentPage') ? $paginator->currentPage() : 1;
return ($currentPage - 1) * $perPage + $rowLoop->iteration; return ($currentPage - 1) * $perPage + $rowLoop->iteration;
}), }),
Tables\Columns\TextColumn::make('plant.name') Tables\Columns\TextColumn::make('plant.name')
@@ -254,14 +252,14 @@ class MachineResource extends Resource
->label('Import Machines') ->label('Import Machines')
->color('warning') ->color('warning')
->importer(MachineImporter::class) ->importer(MachineImporter::class)
->visible(function() { ->visible(function () {
return Filament::auth()->user()->can('view import machine'); return Filament::auth()->user()->can('view import machine');
}), }),
ExportAction::make() ExportAction::make()
->label('Export Machines') ->label('Export Machines')
->color('warning') ->color('warning')
->exporter(MachineExporter::class) ->exporter(MachineExporter::class)
->visible(function() { ->visible(function () {
return Filament::auth()->user()->can('view export machine'); return Filament::auth()->user()->can('view export machine');
}), }),
]); ]);