feat: tambah kehadiran peserta per kegiatan via RelationManager
This commit is contained in:
@@ -5,6 +5,7 @@ namespace App\Filament\Resources\Activities;
|
||||
use App\Filament\Resources\Activities\Pages\CreateActivity;
|
||||
use App\Filament\Resources\Activities\Pages\EditActivity;
|
||||
use App\Filament\Resources\Activities\Pages\ListActivities;
|
||||
use App\Filament\Resources\Activities\RelationManagers\ParticipantsRelationManager;
|
||||
use App\Filament\Resources\Activities\Schemas\ActivityForm;
|
||||
use App\Filament\Resources\Activities\Tables\ActivitiesTable;
|
||||
use App\Models\Activity;
|
||||
@@ -29,6 +30,13 @@ class ActivityResource extends Resource
|
||||
return ActivitiesTable::configure($table);
|
||||
}
|
||||
|
||||
public static function getRelations(): array
|
||||
{
|
||||
return [
|
||||
ParticipantsRelationManager::class,
|
||||
];
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Activities\RelationManagers;
|
||||
|
||||
use Filament\Actions\AttachAction;
|
||||
use Filament\Actions\BulkActionGroup;
|
||||
use Filament\Actions\DetachBulkAction;
|
||||
use Filament\Actions\EditAction;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\Textarea;
|
||||
use Filament\Resources\RelationManagers\RelationManager;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
class ParticipantsRelationManager extends RelationManager
|
||||
{
|
||||
protected static string $relationship = 'participants';
|
||||
protected static ?string $title = 'Kehadiran Peserta';
|
||||
|
||||
public function form(Schema $schema): Schema
|
||||
{
|
||||
return $schema->components([
|
||||
Select::make('status')
|
||||
->options(['hadir' => 'Hadir', 'izin' => 'Izin', 'alpha' => 'Alpha'])
|
||||
->default('hadir')->required(),
|
||||
Textarea::make('notes')->label('Catatan')->rows(2),
|
||||
]);
|
||||
}
|
||||
|
||||
public function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->recordTitleAttribute('name')
|
||||
->columns([
|
||||
TextColumn::make('name')->label('Anggota')->searchable(),
|
||||
TextColumn::make('pivot.status')->label('Status')->badge()
|
||||
->color(fn ($state) => match ($state) {
|
||||
'hadir' => 'success',
|
||||
'izin' => 'warning',
|
||||
'alpha' => 'danger',
|
||||
default => 'gray',
|
||||
}),
|
||||
TextColumn::make('pivot.notes')->label('Catatan')->placeholder('-'),
|
||||
])
|
||||
->headerActions([
|
||||
AttachAction::make()->preloadRecordSelect()
|
||||
->form(fn (AttachAction $action) => [
|
||||
$action->getRecordSelect(),
|
||||
Select::make('status')
|
||||
->options(['hadir' => 'Hadir', 'izin' => 'Izin', 'alpha' => 'Alpha'])
|
||||
->default('hadir')->required(),
|
||||
Textarea::make('notes')->label('Catatan')->rows(2),
|
||||
]),
|
||||
])
|
||||
->recordActions([EditAction::make()])
|
||||
->toolbarActions([BulkActionGroup::make([DetachBulkAction::make()])]);
|
||||
}
|
||||
}
|
||||
@@ -33,6 +33,7 @@ class Activity extends Model
|
||||
|
||||
public function participants(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(User::class, 'activity_member');
|
||||
return $this->belongsToMany(User::class, 'activity_member')
|
||||
->withPivot('status', 'notes');
|
||||
}
|
||||
}
|
||||
|
||||
+2
-1
@@ -40,7 +40,8 @@ class User extends Authenticatable implements FilamentUser
|
||||
|
||||
public function activities(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(Activity::class, 'activity_member');
|
||||
return $this->belongsToMany(Activity::class, 'activity_member')
|
||||
->withPivot('status', 'notes');
|
||||
}
|
||||
|
||||
public function statusLogs(): HasMany
|
||||
|
||||
Reference in New Issue
Block a user