39 lines
1.0 KiB
PHP
39 lines
1.0 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Resources\StudentResource\Pages;
|
|
|
|
use App\Filament\Resources\StudentResource;
|
|
use App\Models\Student;
|
|
use App\Models\User;
|
|
use Carbon\Carbon;
|
|
use Filament\Actions;
|
|
use Filament\Notifications\Notification;
|
|
use Filament\Resources\Pages\CreateRecord;
|
|
use Spatie\Permission\Models\Role;
|
|
|
|
class CreateStudent extends CreateRecord
|
|
{
|
|
protected static string $resource = StudentResource::class;
|
|
|
|
protected function mutateFormDataBeforeCreate(array $data): array
|
|
{
|
|
$parentRole = Role::where('name', 'parent')->first();
|
|
|
|
$birthDate = Carbon::parse($data['birth_date']);
|
|
$password = $birthDate->format('dmY') . $data['nis'];
|
|
|
|
$parentUser = User::updateOrCreate(
|
|
['email' => $data['email']],
|
|
[
|
|
'name' => $data['parent_name'],
|
|
'password' => bcrypt($password),
|
|
'phone' => $data['parent_phone'],
|
|
]
|
|
);
|
|
|
|
$parentUser->assignRole($parentRole);
|
|
|
|
return $data;
|
|
}
|
|
}
|