sistem-akademik/app/Filament/Resources/StudentResource.php
2025-04-11 22:56:42 +07:00

151 lines
5.1 KiB
PHP

<?php
namespace App\Filament\Resources;
use App\Filament\Resources\StudentResource\Pages;
use App\Models\ClassRoom;
use App\Models\Student;
use Filament\Forms;
use Filament\Forms\Form;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
class StudentResource extends Resource
{
protected static ?string $model = Student::class;
protected static ?string $navigationIcon = 'heroicon-o-users';
protected static ?string $navigationGroup = 'Student Management';
public static function form(Form $form): Form
{
return $form
->schema([
Forms\Components\Section::make('Informasi Siswa')
->schema([
Forms\Components\TextInput::make('nis')
->label('NIS')
->required()
->maxLength(20),
Forms\Components\TextInput::make('full_name')
->label('Full Name')
->required()
->maxLength(100),
Forms\Components\Select::make('gender')
->label('Gender')
->options([
'L' => 'L',
'P' => 'P',
])
->required(),
Forms\Components\DatePicker::make('birth_date')
->label('Birth Date')
->required(),
Forms\Components\TextInput::make('birth_place')
->label('Birth Place')
->required()
->maxLength(100),
Forms\Components\TextInput::make('phone')
->label('Phone')
->maxLength(15),
Forms\Components\TextInput::make('email')
->label('Email')
->email()
->maxLength(100),
Forms\Components\Select::make('class_id')
->label('Class')
->options(
fn () => \App\Models\ClassRoom::pluck('class_name', 'id')->toArray()
)
->searchable()
->required(),
Forms\Components\TextInput::make('parent_name')
->label("Parent's Name")
->required()
->maxLength(100),
Forms\Components\TextInput::make('parent_phone')
->label("Parent's Phone")
->maxLength(15),
Forms\Components\Textarea::make('address')
->label('Address')
->rows(3),
])
->columns(2),
]);
}
public static function table(Table $table): Table
{
return $table
->columns([
Tables\Columns\TextColumn::make('nis')
->label('NIS')
->searchable(),
Tables\Columns\TextColumn::make('full_name')
->label('Name')
->searchable()
->sortable(),
Tables\Columns\TextColumn::make('gender')
->label('Gender')
->sortable(),
Tables\Columns\TextColumn::make('birth_place')
->label('Birth Place'),
Tables\Columns\TextColumn::make('birth_date')
->label('Birth Date')
->date(),
Tables\Columns\TextColumn::make('classRoom.class_name')
->label('Class')
->sortable()
->searchable(),
Tables\Columns\TextColumn::make('parent_name')
->label("Parent's Name"),
Tables\Columns\TextColumn::make('created_at')
->dateTime()
->sortable()
->toggleable(isToggledHiddenByDefault: true),
])
->filters([
//
])
->actions([
Tables\Actions\ViewAction::make(),
Tables\Actions\EditAction::make(),
])
->bulkActions([
Tables\Actions\BulkActionGroup::make([
Tables\Actions\DeleteBulkAction::make(),
]),
]);
}
public static function getRelations(): array
{
return [
//
];
}
public static function getPages(): array
{
return [
'index' => Pages\ListStudents::route('/'),
'create' => Pages\CreateStudent::route('/create'),
'edit' => Pages\EditStudent::route('/{record}/edit'),
];
}
}