CreateStudent.php 1.4 KB

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