| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- <?php
- namespace App\Filament\Resources\StudentResource\Pages;
- use App\Filament\Resources\StudentResource;
- use Filament\Resources\Pages\CreateRecord;
- class CreateStudent extends CreateRecord
- {
- protected static string $resource = StudentResource::class;
- protected string $view = 'filament.resources.student-resource.pages.create-student';
- protected static bool $canCreateAnother = false;
- public function getTitle(): string
- {
- return '创建学生';
- }
- public function getSubheading(): ?string
- {
- return null;
- }
- protected function mutateFormDataBeforeCreate(array $data): array
- {
- $currentUser = auth()->user();
- // 如果是老师登录,自动设置 teacher_id
- if ($currentUser?->isTeacher() ?? false) {
- $data['teacher_id'] = $currentUser->teacher?->teacher_id;
- }
- return $data;
- }
- protected function getRedirectUrl(): string
- {
- return $this->getResource()::getUrl('index');
- }
- protected function getCreatedNotificationTitle(): ?string
- {
- return '学生创建成功';
- }
- protected function getCreatedNotification(): ?\Filament\Notifications\Notification
- {
- return \Filament\Notifications\Notification::make()
- ->success()
- ->title('学生创建成功')
- ->body('学生信息已成功保存。');
- }
- }
|