CreateStudent.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. namespace App\Filament\Resources\StudentResource\Pages;
  3. use App\Filament\Resources\StudentResource;
  4. use Filament\Resources\Pages\CreateRecord;
  5. class CreateStudent extends CreateRecord
  6. {
  7. protected static string $resource = StudentResource::class;
  8. protected string $view = 'filament.resources.student-resource.pages.create-student';
  9. protected static bool $canCreateAnother = false;
  10. public function getTitle(): string
  11. {
  12. return '创建学生';
  13. }
  14. public function getSubheading(): ?string
  15. {
  16. return null;
  17. }
  18. protected function mutateFormDataBeforeCreate(array $data): array
  19. {
  20. $currentUser = auth()->user();
  21. // 如果是老师登录,自动设置 teacher_id
  22. if ($currentUser?->isTeacher() ?? false) {
  23. $data['teacher_id'] = $currentUser->teacher?->teacher_id;
  24. }
  25. return $data;
  26. }
  27. protected function getRedirectUrl(): string
  28. {
  29. return $this->getResource()::getUrl('index');
  30. }
  31. protected function getCreatedNotificationTitle(): ?string
  32. {
  33. return '学生创建成功';
  34. }
  35. protected function getCreatedNotification(): ?\Filament\Notifications\Notification
  36. {
  37. return \Filament\Notifications\Notification::make()
  38. ->success()
  39. ->title('学生创建成功')
  40. ->body('学生信息已成功保存。');
  41. }
  42. }