Refactor plant selection options by authenticated user's plant ID.
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user