where("role", "student")->where("school_id", Auth::user()->school_id); } /** * @throws Exception */ public static function table(Table $table): Table { return $table ->columns([ Tables\Columns\TextColumn::make("name")->label(__("Full name"))->searchable(), Tables\Columns\TextColumn::make('grade')->label(__("Grade")), Tables\Columns\TextColumn::make('iin')->label(__("iin")), ]) ->paginated([20]) ->filters([ Tables\Filters\SelectFilter::make('grade') ->label('Class') ->options([ '1В' => '1В', '2Г' => '2Г', '30' => '30', '40' => '40', '50' => '50', '60' => '60', '70' => '70', ]), ]) ->actions([ Tables\Actions\EditAction::make()->hiddenLabel(), Action::make('addCard') ->hiddenLabel() ->icon('heroicon-o-credit-card') ->modalHeading('Add Card') ->modalWidth('md') ->form([ TextInput::make('card_id') ->label('Scan card') ->numeric() ->autofocus() ->required(), ]) ->action(function (array $data, User $record) { if (!empty($data['card_id'])) { $card = Card::firstOrCreate( ['card_id' => $data['card_id']], ['user_id' => $record->id] ); Notification::make() ->title($card->wasRecentlyCreated ? 'success' : 'information') ->body($card->wasRecentlyCreated ? 'New card success added!' : 'This card already exists!.') ->send(); } else { Notification::make() ->title('error') ->body('field "card_id" is required!') ->danger() ->send(); } }) ->after(function (User $user) { $user->load('cards'); }), Tables\Actions\DeleteAction::make()->hiddenLabel(), ]); } public static function form(Form $form): Form { return $form ->schema([ Forms\Components\TextInput::make('name')->required()->maxLength(255), Forms\Components\TextInput::make('username')->required()->maxLength(255), Forms\Components\TextInput::make('status')->required()->maxLength(255)->default('active'), Forms\Components\TextInput::make('email')->email()->maxLength(255), Forms\Components\TextInput::make('password')->password()->required()->maxLength(255), Forms\Components\Toggle::make('free')->required(), Forms\Components\TextInput::make('grade')->maxLength(255), Forms\Components\TextInput::make('balance')->required()->numeric()->default(0), Forms\Components\TextInput::make('school_id')->numeric(), Forms\Components\TextInput::make('phone')->tel()->maxLength(255), ]); } public static function getPages(): array { return [ 'index' => Pages\ListUsers::route('/'), // 'create' => Pages\CreateUser::route('/create'), // 'edit' => Pages\EditUser::route('/{record}/edit'), ]; } }