From 5f4945d997e3bee073b7c82a3b9899a8f40569c7 Mon Sep 17 00:00:00 2001 From: dhanabalan Date: Mon, 29 Sep 2025 11:41:30 +0530 Subject: [PATCH] Add plant relationship to UserResource form and table --- app/Filament/Resources/UserResource.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/app/Filament/Resources/UserResource.php b/app/Filament/Resources/UserResource.php index bb62d11..504c590 100644 --- a/app/Filament/Resources/UserResource.php +++ b/app/Filament/Resources/UserResource.php @@ -19,11 +19,12 @@ use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\SoftDeletingScope; use Illuminate\Support\Facades\Hash; + class UserResource extends Resource { protected static ?string $model = User::class; - protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack'; + protected static ?string $navigationIcon = 'heroicon-c-user-group'; protected static ?string $navigationGroup = 'User Management'; @@ -31,6 +32,13 @@ class UserResource extends Resource { return $form ->schema([ + Forms\Components\Select::make('plant_id') + ->relationship('plant', 'name') + ->nullable() + ->reactive() + ->default(function () { + return optional(User::latest()->first())->plant_id; + }), Forms\Components\TextInput::make('name') ->required() ->autofocus() @@ -94,6 +102,11 @@ class UserResource extends Resource $currentPage = method_exists($paginator, 'currentPage') ? $paginator->currentPage() : 1; return ($currentPage - 1) * $perPage + $rowLoop->iteration; }), + Tables\Columns\TextColumn::make('plant.name') + ->label('Plant') + ->alignCenter() + ->sortable() + ->searchable(), Tables\Columns\TextColumn::make('name') ->label('User Name') ->alignCenter()