Skip to content

Commit

Permalink
binding relative entities in admin panel
Browse files Browse the repository at this point in the history
  • Loading branch information
romo4ko committed Oct 26, 2024
1 parent 7c9dcc3 commit 7010552
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 18 deletions.
2 changes: 1 addition & 1 deletion app/Filament/Resources/AchievementResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public static function table(Table $table): Table
//
])
->actions([
Tables\Actions\EditAction::make(),
Tables\Actions\EditAction::make()->label('Управление'),
])
->bulkActions([
Tables\Actions\BulkActionGroup::make([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class EditAchievement extends EditRecord
{
public function getHeading(): string
{
return 'Изменить ачивку';
return 'Управление ачивкой';
}

protected static string $resource = AchievementResource::class;
Expand Down
3 changes: 2 additions & 1 deletion app/Filament/Resources/ChallengeResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public static function form(Form $form): Form
Forms\Components\Select::make('achievement_id')
->label('Ачивка')
->relationship('achievement', 'name')
->searchable()
->nullable(),
FileUpload::make('image')
->rules(['image'])
Expand Down Expand Up @@ -105,7 +106,7 @@ public static function table(Table $table): Table
//
])
->actions([
Tables\Actions\EditAction::make(),
Tables\Actions\EditAction::make()->label('Управление'),
])
->bulkActions([
Tables\Actions\BulkActionGroup::make([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class EditChallenge extends EditRecord
{
public function getHeading(): string
{
return 'Изменить челлендж';
return 'Управление челленджем';
}

protected static string $resource = ChallengeResource::class;
Expand Down
23 changes: 17 additions & 6 deletions app/Filament/Resources/TeamResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,28 +48,28 @@ public static function form(Form $form): Form
Forms\Components\Section::make()
->schema([
Forms\Components\Select::make('users')
->label('Участники')
->label('Участники команды')
->relationship('users', 'name')
->preload()
->multiple(),
Forms\Components\Select::make('achievements')
->label('Достижения')
->label('Достижения команды')
->relationship('achievements', 'name')
->preload()
->multiple(),
])->columns(2),
Forms\Components\Section::make()
->schema([
Forms\Components\Select::make('challenges')
->label('Челленджи')
->label('Челленджи команды')
->relationship('challenges', 'name')
->getOptionLabelFromRecordUsing(
function (Challenge $record) {
return $record->name . ' ' . ($record->is_finished ? '(Завершён)' : '');
})
->preload()
->multiple(),
])->columns(2)
])->columns(1)
])->columns(1);
}

Expand All @@ -90,7 +90,8 @@ public static function table(Table $table): Table
fn($record) => $record->users->count() > 0
? 'success' : 'danger'
)
->label('Участников'),
->label('Участников')
->sortable(),
Tables\Columns\TextColumn::make('achievements_count')
->counts('achievements')
->badge()
Expand All @@ -99,12 +100,22 @@ public static function table(Table $table): Table
? 'success' : 'danger'
)
->label('Достижений')
->sortable(),
Tables\Columns\TextColumn::make('challenges_count')
->counts('challenges')
->badge()
->color(
fn($record) => $record->challenges->count() > 0
? 'success' : 'danger'
)
->label('Челленджей')
->sortable(),
])
->filters([
//
])
->actions([
Tables\Actions\EditAction::make(),
Tables\Actions\EditAction::make()->label('Управление'),
])
->bulkActions([
Tables\Actions\BulkActionGroup::make([
Expand Down
2 changes: 1 addition & 1 deletion app/Filament/Resources/TeamResource/Pages/EditTeam.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class EditTeam extends EditRecord
{
public function getHeading(): string
{
return 'Изменить команду';
return 'Управление командой';
}
protected static string $resource = TeamResource::class;

Expand Down
52 changes: 46 additions & 6 deletions app/Filament/Resources/UserResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\Filament\Resources\UserResource\Pages;
use App\Filament\Resources\UserResource\RelationManagers;
use App\Models\Challenge;
use App\Models\User;
use Filament\Forms;
use Filament\Forms\Form;
Expand Down Expand Up @@ -62,6 +63,31 @@ public static function form(Form $form): Form
Forms\Components\TextInput::make('patronymic')->label('Отчество'),
Forms\Components\Textarea::make('about')->label('О себе')->rows(5),
])->columns(),
Forms\Components\Section::make()
->schema([
Forms\Components\Select::make('teams')
->label('Команды, в которых состоит пользователь')
->relationship('teams', 'name')
->preload()
->multiple(),
Forms\Components\Select::make('achievements')
->label('Достижения пользователя')
->relationship('achievements', 'name')
->preload()
->multiple(),
])->columns(2),
Forms\Components\Section::make()
->schema([
Forms\Components\Select::make('challenges')
->label('Челленджи пользователя')
->relationship('challenges', 'name')
->getOptionLabelFromRecordUsing(
function (Challenge $record) {
return $record->name . ' ' . ($record->is_finished ? '(Завершён)' : '');
})
->preload()
->multiple(),
])->columns(1)
]);
}

Expand All @@ -76,15 +102,29 @@ public static function table(Table $table): Table
->label('Фамилия')
->default('-')
->searchable(),
Tables\Columns\TextColumn::make('patronymic')
->label('Отчество')
->default('-')
->searchable(),
Tables\Columns\TextColumn::make('email')
->label('Почта')
->searchable(),
CheckboxColumn::make('is_confirmed')
->label('Верифицирован'),
->label('Проверен'),
Tables\Columns\TextColumn::make('challenges_count')
->counts('challenges')
->badge()
->color(
fn($record) => $record->challenges->count() > 0
? 'success' : 'danger'
)
->label('Челленджей')
->sortable(),
Tables\Columns\TextColumn::make('achievements_count')
->counts('achievements')
->badge()
->color(
fn($record) => $record->achievements->count() > 0
? 'success' : 'danger'
)
->label('Достижений')
->sortable()
])
->defaultSort('created_at', 'desc')
->filters([
Expand All @@ -94,7 +134,7 @@ public static function table(Table $table): Table
->label('Не верифицированные'),
])
->actions([
Tables\Actions\EditAction::make(),
Tables\Actions\EditAction::make()->label('Управление'),
])
->bulkActions([
Tables\Actions\BulkActionGroup::make([
Expand Down
2 changes: 1 addition & 1 deletion app/Filament/Resources/UserResource/Pages/EditUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class EditUser extends EditRecord
{
public function getHeading(): string
{
return 'Изменить пользователя';
return 'Управление пользователем';
}

protected static string $resource = UserResource::class;
Expand Down

0 comments on commit 7010552

Please sign in to comment.