schema([ Forms\Components\Select::make('plant_id') ->label('Plant') ->reactive() ->relationship('plant', 'name') ->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(), Forms\Components\Select::make('item_id') ->label('Item') ->reactive() ->options(function (callable $get) { $plantId = $get('plant_id'); if (empty($plantId)) { return []; } return \App\Models\Item::where('plant_id', $plantId)->pluck('code', 'id'); }) ->required(), Forms\Components\TextInput::make('sticker1') ->label('Sticker Label 1') ->required(), Forms\Components\TextInput::make('sticker2') ->label('Sticker Label 2'), Forms\Components\TextInput::make('sticker3') ->label('Sticker Label 3'), Forms\Components\TextInput::make('sticker4') ->label('Sticker Label 4'), Forms\Components\TextInput::make('sticker5') ->label('Sticker Label 5'), Forms\Components\Hidden::make('created_by') ->label('Created By') ->default(Filament::auth()->user()?->name), Forms\Components\Hidden::make('updated_by') ->label('Updated By') ->default(Filament::auth()->user()?->name), ]); } public static function table(Table $table): Table { return $table ->columns([ Tables\Columns\TextColumn::make('No.') ->label('No.') ->getStateUsing(function ($record, $livewire, $column, $rowLoop) { $paginator = $livewire->getTableRecords(); $perPage = method_exists($paginator, 'perPage') ? $paginator->perPage() : 10; $currentPage = method_exists($paginator, 'currentPage') ? $paginator->currentPage() : 1; return ($currentPage - 1) * $perPage + $rowLoop->iteration; }), Tables\Columns\TextColumn::make('plant.name') ->label('Plant') ->alignCenter() ->sortable(), Tables\Columns\TextColumn::make('item.code') ->label('Item Code') ->alignCenter() ->sortable(), Tables\Columns\TextColumn::make('sticker1') ->label('Sticker Label 1') ->alignCenter() ->sortable(), Tables\Columns\TextColumn::make('sticker2') ->label('Sticker Label 2') ->alignCenter() ->sortable(), Tables\Columns\TextColumn::make('sticker3') ->label('Sticker Label 3') ->alignCenter() ->sortable(), Tables\Columns\TextColumn::make('sticker4') ->label('Sticker Label 4') ->alignCenter() ->sortable(), Tables\Columns\TextColumn::make('sticker5') ->label('Sticker Label 5') ->alignCenter() ->sortable(), Tables\Columns\TextColumn::make('created_at') ->label('Created At') ->alignCenter() ->dateTime() ->sortable() ->toggleable(isToggledHiddenByDefault: true), Tables\Columns\TextColumn::make('updated_at') ->label('Updated At') ->alignCenter() ->dateTime() ->sortable() ->toggleable(isToggledHiddenByDefault: true), Tables\Columns\TextColumn::make('deleted_at') ->label('Deleted At') ->alignCenter() ->dateTime() ->sortable() ->toggleable(isToggledHiddenByDefault: true), ]) ->filters([ Tables\Filters\TrashedFilter::make(), ]) ->actions([ Tables\Actions\ViewAction::make(), Tables\Actions\EditAction::make(), ]) ->bulkActions([ Tables\Actions\BulkActionGroup::make([ Tables\Actions\DeleteBulkAction::make(), Tables\Actions\ForceDeleteBulkAction::make(), Tables\Actions\RestoreBulkAction::make(), ]), ]) ->headerActions([ ImportAction::make() ->label('Import Sticker Mapping Masters') ->color('warning') ->importer(StickerMappingMasterImporter::class) ->visible(function() { return Filament::auth()->user()->can('view import sticker mapping master'); }), ExportAction::make() ->label('Export Sticker Mapping Masters') ->color('warning') ->exporter(StickerMappingMasterExporter::class) ->visible(function() { return Filament::auth()->user()->can('view export sticker mapping master'); }), ]); } public static function getRelations(): array { return [ // ]; } public static function getPages(): array { return [ 'index' => Pages\ListStickerMappingMasters::route('/'), 'create' => Pages\CreateStickerMappingMaster::route('/create'), 'view' => Pages\ViewStickerMappingMaster::route('/{record}'), 'edit' => Pages\EditStickerMappingMaster::route('/{record}/edit'), ]; } public static function getEloquentQuery(): Builder { return parent::getEloquentQuery() ->withoutGlobalScopes([ SoftDeletingScope::class, ]); } }