Add rol al registrar nuevo usuario.
This commit is contained in:
parent
3207ce7c56
commit
7c859accc0
@ -14,17 +14,18 @@ class UserController extends Controller
|
|||||||
public function register(Request $request)
|
public function register(Request $request)
|
||||||
{
|
{
|
||||||
$request->validate([
|
$request->validate([
|
||||||
'email' => 'required|email|unique:users'
|
'email' => 'required|email|unique:users',
|
||||||
|
'rol'=> 'required|numeric|size:2'
|
||||||
]);
|
]);
|
||||||
$userAuth = auth()->user()->roles[0]->name;
|
$userAuth = auth()->user()->roles[0]->name;
|
||||||
if ($userAuth === "Admin") {
|
if ($userAuth == "Admin") {
|
||||||
$user = new User();
|
$user = new User();
|
||||||
$user->name = "null";
|
$user->name = "null";
|
||||||
$user->lastname = "null";
|
$user->lastname = "null";
|
||||||
$user->email = $request->email;
|
$user->email = $request->email;
|
||||||
$user->password = "null";
|
$user->password = "null";
|
||||||
$user->save();
|
$user->save();
|
||||||
$user->roles()->attach(2);
|
$user->roles()->attach($request->rol);
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'message' => 'Correo registrado exitosamente',
|
'message' => 'Correo registrado exitosamente',
|
||||||
'userAuth' => $user,
|
'userAuth' => $user,
|
||||||
@ -32,7 +33,7 @@ public function register(Request $request)
|
|||||||
} else {
|
} else {
|
||||||
return response()->json([
|
return response()->json([
|
||||||
"status" => 0,
|
"status" => 0,
|
||||||
"message" => "Correo no registrado",
|
"message" => "No eres administrador: Correo no registrado",
|
||||||
], 404);
|
], 404);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user