1
0
mirror of https://github.com/robonen/education-project.git synced 2026-03-20 02:44:31 +00:00
This commit is contained in:
nikden13
2020-12-16 03:13:20 +07:00
parent c93ffe8b0f
commit 045a767774
22 changed files with 231 additions and 54 deletions

View File

@@ -16,10 +16,10 @@ class RegisterController extends Controller
{
public function __invoke(RegisterRequest $request)
{
$role = Role::where('name', $request->get('role'));
$role = Role::where('name', $request->get('role'))->get();
if ($role->isEmpty())
return response()->json('Role not found', 404);
return response()->json(['message'=>'Role not found'], 404);
$user = User::create(array_merge(
$request->only('login', 'class_id'),
@@ -29,29 +29,25 @@ class RegisterController extends Controller
]
));
$user_id = [
'user_id' => $user->id,
];
switch($request->get('role'))
{
case 'headteacher':
HeadTeacher::create($user_id);
$user->headteacher()->create();
break;
case 'teacher':
Teacher::create($user_id);
$user->teacher()->create();
break;
case 'student':
Student::create($user_id);
$user->student()->create();
break;
case 'parent':
Parentt::create($user_id);
$user->parent()->create();
break;
}
return response()->json('ok', 200);
return response()->json(null, 201);
}
}