sistem-akademik/app/Filament/Pages/SchoolInformation.php

127 lines
3.9 KiB
PHP

<?php
namespace App\Filament\Pages;
use Filament\Forms\Components\Grid;
use Filament\Forms\Form;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Components\Textarea;
use Filament\Notifications\Notification;
use Filament\Pages\Page;
use Filament\Forms\Contracts\HasForms;
use Filament\Forms\Concerns\InteractsWithForms;
use App\Models\SchoolInformation as SchoolInformationModel;
use Illuminate\Contracts\Support\Htmlable;
class SchoolInformation extends Page implements HasForms
{
use InteractsWithForms;
protected static ?string $navigationIcon = 'heroicon-o-document-text';
protected static string $view = 'filament.pages.school-information';
protected static ?string $navigationGroup = 'Pengaturan';
protected static ?int $navigationSort = 999;
public static function canAccess(): bool
{
return auth()->user()?->can('page_SchoolInformation');
}
public static function shouldRegisterNavigation(): bool
{
return auth()->user()?->can('page_SchoolInformation');
}
public ?array $data = [];
public ?SchoolInformationModel $record = null;
public function mount(): void
{
$this->record = SchoolInformationModel::firstOrNew();
$this->form->fill($this->record->toArray());
}
public function form(Form $form): Form
{
return $form
->schema([
Grid::make(2)->schema([
TextInput::make('school_name')->label('Nama Sekolah')->required(),
TextInput::make('npsn')
->label('NPSN')
->numeric()
->nullable(),
TextInput::make('nss')
->label('NSS')
->nullable(),
Textarea::make('address')
->label('Alamat Sekolah')
->nullable(),
TextInput::make('postal_code')
->label('Kode Pos')
->numeric()
->nullable()
->default(null),
TextInput::make('sub_district')
->label('Desa / Kelurahan')
->nullable(),
TextInput::make('district')
->label('Kecamatan')
->nullable(),
TextInput::make('city')
->label('Kota / Kabupaten')
->nullable(),
TextInput::make('province')
->label('Provinsi')
->nullable(),
TextInput::make('email')
->label('Email')
->nullable(),
TextInput::make('headmaster_name')
->label('Nama Kepala Sekolah')
->nullable(),
TextInput::make('headmaster_nip')
->label('NIP Kepala Sekolah')
->nullable(),
TextInput::make('phase')
->label('Fase')
->nullable(),
])
])
->model($this->record)
->statePath('data');
}
public function save(): void
{
$this->record->fill($this->data)->save();
Notification::make()
->title('Success')
->body('Data saved successfully.')
->success()
->send();
}
public function getTitle(): string | Htmlable
{
return 'Informasi Sekolah'; // Contoh jika nama laporan dinamis
}
public static function getNavigationLabel(): string
{
return 'Informasi Sekolah';
}
public static function getBreadcrumb(): string
{
return 'Informasi Sekolah';
}
public static function getPluralModelLabel(): string
{
return 'Informasi Sekolah';
}
}