Refactor plant selection options in InvoiceFinder to filter by authenticated user's plant ID.

This commit is contained in:
dhanabalan
2025-09-29 18:21:13 +05:30
parent 368d115124
commit ece893ae84

View File

@@ -5,6 +5,7 @@ namespace App\Filament\Pages;
use App\Models\LocatorInvoiceValidation; use App\Models\LocatorInvoiceValidation;
use App\Models\PalletValidation; use App\Models\PalletValidation;
use App\Models\Plant; use App\Models\Plant;
use Filament\Facades\Filament;
use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Auth;
use Filament\Forms\Contracts\HasForms; use Filament\Forms\Contracts\HasForms;
use Filament\Forms\Concerns\InteractsWithForms; use Filament\Forms\Concerns\InteractsWithForms;
@@ -41,8 +42,12 @@ class InvoiceFinder extends Page implements HasForms
Section::make('') // You can give your section a title or leave it blank Section::make('') // You can give your section a title or leave it blank
->schema([ ->schema([
Select::make('plant_id') Select::make('plant_id')
->options(Plant::pluck('name', 'id'))
->label('Plant') ->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() ->reactive()
->required(), ->required(),
TextInput::make('scan_invoice') TextInput::make('scan_invoice')