Refactor plant selection logic to filter by user-specific plant ID in various resources
This commit is contained in:
@@ -419,7 +419,11 @@ class GuardPatrolEntryResource extends Resource
|
|||||||
->label('Import Guard Patrol Entries')
|
->label('Import Guard Patrol Entries')
|
||||||
->form([
|
->form([
|
||||||
Select::make('plant_id')
|
Select::make('plant_id')
|
||||||
->options(Plant::pluck('name', 'id')->toArray())
|
// ->options(Plant::pluck('name', 'id')->toArray())
|
||||||
|
->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();
|
||||||
|
})
|
||||||
->label('Select Plant')
|
->label('Select Plant')
|
||||||
->reactive()
|
->reactive()
|
||||||
->required()
|
->required()
|
||||||
|
|||||||
@@ -306,7 +306,11 @@ class InvoiceValidationResource extends Resource
|
|||||||
->label('Import Serial Invoice')
|
->label('Import Serial Invoice')
|
||||||
->form([
|
->form([
|
||||||
Select::make('plant_id')
|
Select::make('plant_id')
|
||||||
->options(Plant::pluck('name', 'id')->toArray()) // Fetch plant names and IDs
|
// ->options(Plant::pluck('name', 'id')->toArray()) // Fetch plant names and IDs
|
||||||
|
->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();
|
||||||
|
})
|
||||||
->label('Select Plant')
|
->label('Select Plant')
|
||||||
->required()
|
->required()
|
||||||
->default(function () {
|
->default(function () {
|
||||||
@@ -623,7 +627,11 @@ class InvoiceValidationResource extends Resource
|
|||||||
->form([
|
->form([
|
||||||
|
|
||||||
Select::make('plant_id')
|
Select::make('plant_id')
|
||||||
->options(Plant::pluck('name', 'id')->toArray()) // Fetch plant names and IDs
|
// ->options(Plant::pluck('name', 'id')->toArray()) // Fetch plant names and IDs
|
||||||
|
->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();
|
||||||
|
})
|
||||||
->label('Select Plant')
|
->label('Select Plant')
|
||||||
->required()
|
->required()
|
||||||
->default(function () {
|
->default(function () {
|
||||||
|
|||||||
@@ -501,7 +501,11 @@ class LocatorInvoiceValidationResource extends Resource
|
|||||||
->label('Import Invoice')
|
->label('Import Invoice')
|
||||||
->form([
|
->form([
|
||||||
Select::make('plant_id')
|
Select::make('plant_id')
|
||||||
->options(Plant::pluck('name', 'id')->toArray())
|
// ->options(Plant::pluck('name', 'id')->toArray())
|
||||||
|
->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();
|
||||||
|
})
|
||||||
->label('Select Plant')
|
->label('Select Plant')
|
||||||
->required()
|
->required()
|
||||||
->default(function () {
|
->default(function () {
|
||||||
|
|||||||
@@ -514,7 +514,11 @@ class PalletValidationResource extends Resource
|
|||||||
->schema([
|
->schema([
|
||||||
Forms\Components\Select::make('plant')
|
Forms\Components\Select::make('plant')
|
||||||
->label('Select Plant')
|
->label('Select Plant')
|
||||||
->options(Plant::pluck('name', 'id')->toArray())
|
// ->options(Plant::pluck('name', 'id')->toArray())
|
||||||
|
->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()
|
->required()
|
||||||
->reactive()
|
->reactive()
|
||||||
->columnSpan(2),
|
->columnSpan(2),
|
||||||
|
|||||||
@@ -285,7 +285,11 @@ class SerialValidationResource extends Resource
|
|||||||
->label('Import Serial Invoice')
|
->label('Import Serial Invoice')
|
||||||
->form([
|
->form([
|
||||||
Select::make('plant_id')
|
Select::make('plant_id')
|
||||||
->options(Plant::pluck('name', 'id')->toArray()) // Fetch plant names and IDs
|
// ->options(Plant::pluck('name', 'id')->toArray()) // Fetch plant names and IDs
|
||||||
|
->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();
|
||||||
|
})
|
||||||
->label('Select Plant')
|
->label('Select Plant')
|
||||||
->required()
|
->required()
|
||||||
->default(function () {
|
->default(function () {
|
||||||
|
|||||||
@@ -380,7 +380,11 @@ class WeightValidationResource extends Resource
|
|||||||
->label('Import OBD Weight Invoice')
|
->label('Import OBD Weight Invoice')
|
||||||
->form([
|
->form([
|
||||||
Select::make('plant_id')
|
Select::make('plant_id')
|
||||||
->options(Plant::pluck('name', 'id')->toArray())
|
// ->options(Plant::pluck('name', 'id')->toArray())
|
||||||
|
->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();
|
||||||
|
})
|
||||||
->label('Select Plant')
|
->label('Select Plant')
|
||||||
->required()
|
->required()
|
||||||
->default(function () {
|
->default(function () {
|
||||||
|
|||||||
Reference in New Issue
Block a user