Refactor plant selection options by authenticated user's plant ID.

This commit is contained in:
dhanabalan
2025-09-29 18:26:35 +05:30
parent ece893ae84
commit 85ebccd22c
8 changed files with 50 additions and 14 deletions

View File

@@ -7,6 +7,7 @@ use App\Models\Plant;
use App\Models\ProductionQuantity;
use App\Models\QualityValidation;
use App\Models\StickerMaster;
use Filament\Facades\Filament;
use Filament\Forms\Components\Actions;
use Filament\Forms\Components\Actions\Action;
use Filament\Forms\Form;
@@ -55,8 +56,12 @@ class DataSendToSap extends Page implements HasForms
->statePath('data')
->schema([
Select::make('plant_id')
->options(Plant::pluck('name', 'id'))
->label('Plant')
// ->options(Plant::pluck('name', 'id'))
->options(function (callable $get) {
$userHas = Filament::auth()->user()->plant_id;
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray();
})
->reactive()
->required()
->afterStateUpdated(function ($state, $set, callable $get) {

View File

@@ -4,6 +4,7 @@ namespace App\Filament\Pages;
use App\Filament\Widgets\GuardPatrolDayChart;
use App\Models\Plant;
use Filament\Facades\Filament;
use Filament\Pages\Page;
use Filament\Pages\Dashboard\Concerns\HasFiltersForm;
use Filament\Forms\Form;
@@ -34,8 +35,12 @@ class GuardPatrolDayCount extends Page
->statePath('filters')
->schema([
Select::make('plant')
->options(Plant::pluck('name', 'id'))
->label('Select Plant')
// ->options(Plant::pluck('name', 'id'))
->options(function (callable $get) {
$userHas = Filament::auth()->user()->plant_id;
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray();
})
->reactive()
->afterStateUpdated(function ($state) {
session(['selected_plant' => $state]);

View File

@@ -5,6 +5,7 @@ namespace App\Filament\Pages;
use App\Models\GuardPatrolEntry;
use App\Models\Plant;
use Carbon\Carbon;
use Filament\Facades\Filament;
use Filament\Forms\Components\DatePicker;
use Filament\Forms\Components\DateTimePicker;
use Filament\Forms\Components\Select;
@@ -38,8 +39,12 @@ class GuardPatrolEntryDashboard extends Page
->statePath('filters') // Explicitly set where to store form data
->schema([
Select::make('plant')
->options(Plant::pluck('name', 'id'))
->label('Select Plant')
// ->options(Plant::pluck('name', 'id'))
->options(function (callable $get) {
$userHas = Filament::auth()->user()->plant_id;
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray();
})
->reactive()
->required()
->afterStateUpdated(function ($state, callable $set, callable $get){

View File

@@ -8,6 +8,7 @@ use App\Models\CheckPointTime;
use App\Models\GuardPatrolEntry;
use App\Models\Plant;
use Carbon\Carbon;
use Filament\Facades\Filament;
use Filament\Pages\Page;
use Filament\Pages\Dashboard\Concerns\HasFiltersForm;
use Filament\Forms\Form;
@@ -47,8 +48,12 @@ class GuardPatrolHourlyCount extends Page
->statePath('filters')
->schema([
Select::make('plant')
->options(Plant::pluck('name', 'id'))
->label('Select Plant')
//->options(Plant::pluck('name', 'id'))
->options(function (callable $get) {
$userHas = Filament::auth()->user()->plant_id;
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray();
})
->reactive()
->required()
->afterStateUpdated(function ($state,callable $set) {

View File

@@ -69,7 +69,11 @@ class LocatorValidation extends Page implements HasForms
Select::make('plant_id')
->label('Plant')
->reactive()
->options(Plant::pluck('name', 'id'))
//->options(Plant::pluck('name', 'id'))
->options(function (callable $get) {
$userHas = Filament::auth()->user()->plant_id;
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray();
})
->required(),
TextInput::make('scan_pallet_no')
->label('Scan Pallet No')

View File

@@ -64,11 +64,15 @@ class PalletFromLocator extends Page implements HasForms
Section::make('')
->schema([
Select::make('plant_id')
->options(Plant::pluck('name', 'id'))
->label('Plant')
->reactive()
->required()
->columnSpan(1)
//->options(Plant::pluck('name', 'id'))
->options(function (callable $get) {
$userHas = Filament::auth()->user()->plant_id;
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray();
})
->disabled(fn (Get $get) => $get('plant_id'))
->afterStateUpdated(function ($state, callable $set, callable $get) {
$plantId = $get('plant_id');

View File

@@ -122,11 +122,15 @@ class StickerReprint extends Page implements HasForms
->schema([
Select::make('plant_id')
->options(Plant::pluck('name', 'id'))
->label('Plant')
->reactive()
->required()
->columnSpan(1)
//->options(Plant::pluck('name', 'id'))
->options(function (callable $get) {
$userHas = Filament::auth()->user()->plant_id;
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray();
})
->default(function () {
return optional(ProductionQuantity::latest()->first())->plant_id;
})

View File

@@ -54,10 +54,14 @@ class UploadSerialLocator extends Page implements HasForms
Section::make('') // You can give your section a title or leave it blank
->schema([
Select::make('plant_id')
->options(Plant::pluck('name', 'id'))
->label('Plant')
->reactive()
->required()
//->options(Plant::pluck('name', 'id'))
->options(function (callable $get) {
$userHas = Filament::auth()->user()->plant_id;
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray();
})
->disabled(fn (Get $get) => $get('scan_serial_number') || $get('scan_locator')) //!empty($get('scan_serial_number'))
->afterStateUpdated(function ($state, callable $set, callable $get) {
$set('scan_serial_number', null);