149 lines
5.0 KiB
PHP
149 lines
5.0 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Resources;
|
|
|
|
use App\Filament\Resources\LearningObjectiveResource\Pages;
|
|
use App\Filament\Resources\LearningObjectiveResource\RelationManagers;
|
|
use App\Models\ClassRoom; // Import ClassRoom model
|
|
use App\Models\LearningObjective;
|
|
use App\Models\Subject; // Import Subject model
|
|
use Filament\Forms;
|
|
use Filament\Forms\Components\Select;
|
|
use Filament\Forms\Form;
|
|
use Filament\Resources\Resource;
|
|
use Filament\Tables;
|
|
use Filament\Tables\Table;
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
|
|
|
class LearningObjectiveResource extends Resource
|
|
{
|
|
protected static ?string $model = LearningObjective::class;
|
|
|
|
protected static ?string $navigationIcon = 'heroicon-o-document-text';
|
|
|
|
protected static ?string $navigationGroup = 'Academic Setup';
|
|
|
|
public static function form(Form $form): Form
|
|
{
|
|
return $form
|
|
->schema([
|
|
Select::make('class_room_id')
|
|
->label('Class Room')
|
|
->required()
|
|
->options(ClassRoom::pluck('class_name', 'id')->toArray())
|
|
->searchable()
|
|
->native(false),
|
|
|
|
Select::make('subject_id')
|
|
->label('Mata Pelajaran')
|
|
->relationship('subject', 'name')
|
|
->required(),
|
|
|
|
// Textarea for description
|
|
Forms\Components\Textarea::make('description')
|
|
->rows(5)
|
|
->cols(10)
|
|
->required()
|
|
->maxLength(65535), // Max length for TEXT type in database
|
|
]);
|
|
}
|
|
|
|
public static function table(Table $table): Table
|
|
{
|
|
return $table
|
|
->columns([
|
|
// Display related Class Room name
|
|
Tables\Columns\TextColumn::make('class.class_name')
|
|
->label('Kelas')
|
|
->searchable()
|
|
->sortable(),
|
|
|
|
// Display related Subject name
|
|
Tables\Columns\TextColumn::make('subject.name')
|
|
->label('Mapel')
|
|
->searchable()
|
|
->sortable(),
|
|
|
|
// Display description, truncate for brevity in table
|
|
Tables\Columns\TextColumn::make('description')
|
|
->label('Deskripsi')
|
|
->searchable()
|
|
->limit(50) // Limit text length in table
|
|
->tooltip(fn (LearningObjective $record): string => $record->description) // Show full text on hover
|
|
->sortable(),
|
|
|
|
// Standard timestamp columns
|
|
Tables\Columns\TextColumn::make('created_at')
|
|
->dateTime()
|
|
->sortable()
|
|
->toggleable(isToggledHiddenByDefault: true),
|
|
Tables\Columns\TextColumn::make('updated_at')
|
|
->dateTime()
|
|
->sortable()
|
|
->toggleable(isToggledHiddenByDefault: true),
|
|
Tables\Columns\TextColumn::make('deleted_at')
|
|
->dateTime()
|
|
->sortable()
|
|
->toggleable(isToggledHiddenByDefault: true), // Show deleted_at if soft deletes are used
|
|
])
|
|
->filters([
|
|
// TrashedFilter works with SoftDeletes trait on the model
|
|
Tables\Filters\TrashedFilter::make(),
|
|
])
|
|
->actions([
|
|
Tables\Actions\EditAction::make(),
|
|
Tables\Actions\DeleteAction::make(), // For soft deleting records
|
|
Tables\Actions\RestoreAction::make(), // For restoring soft-deleted records
|
|
Tables\Actions\ForceDeleteAction::make(), // For permanently deleting records
|
|
])
|
|
->bulkActions([
|
|
Tables\Actions\BulkActionGroup::make([
|
|
Tables\Actions\DeleteBulkAction::make(),
|
|
Tables\Actions\ForceDeleteBulkAction::make(),
|
|
Tables\Actions\RestoreBulkAction::make(),
|
|
]),
|
|
]);
|
|
}
|
|
|
|
public static function getRelations(): array
|
|
{
|
|
return [
|
|
// Define any relation managers here if needed
|
|
];
|
|
}
|
|
|
|
public static function getPages(): array
|
|
{
|
|
return [
|
|
'index' => Pages\ListLearningObjectives::route('/'),
|
|
'create' => Pages\CreateLearningObjective::route('/create'),
|
|
'edit' => Pages\EditLearningObjective::route('/{record}/edit'),
|
|
];
|
|
}
|
|
|
|
public static function getEloquentQuery(): Builder
|
|
{
|
|
|
|
return parent::getEloquentQuery()
|
|
->withoutGlobalScopes([
|
|
SoftDeletingScope::class,
|
|
]);
|
|
}
|
|
|
|
public static function getNavigationLabel(): string
|
|
{
|
|
return 'Tujuan Pembelajaran';
|
|
}
|
|
|
|
public static function getBreadcrumb(): string
|
|
{
|
|
return 'Tujuan Pembelajaran';
|
|
}
|
|
|
|
public static function getPluralModelLabel(): string
|
|
{
|
|
return 'Tujuan Pembelajaran';
|
|
}
|
|
}
|