Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.39 KB | None | 0 0
  1. public function store(Request $request)
  2. {
  3. $validator = Validator::make($request->all(), [
  4. 'name' => 'required|string|max:255',
  5. 'email' => 'required|string|max:255| unique:users',
  6. 'telefono' => 'required|string|max:20',
  7. 'direccion' => 'required|string|max:255',
  8. 'propiedad_id'=> 'required|numeric',
  9. ]);
  10.  
  11. if ($validator->fails())
  12. {
  13. return $this->sendError('Error en los datos',['errors'=>$validator->errors()->all()], 422);
  14. //return response(['errors'=>$validator->errors()->all()], 422);
  15. }
  16.  
  17. $propiedad=Propiedad::find($request->propiedad_id);
  18.  
  19.  
  20. if ($propiedad==null) {
  21. return $this->sendError('Error propiedad no encontrada.',[], 202);
  22. }
  23.  
  24.  
  25. $password=str_random(8);
  26. $validatorPass= Validator::make($password,[
  27. 'password' => 'required|string|max:255| unique:users',
  28. ]);
  29.  
  30. while ($validatorPass->fails()) {
  31. $password=str_random(8);
  32. $validatorPass= Validator::make($password,[
  33. 'password' => 'required|string|max:255| unique:users',
  34. ]);
  35. }
  36.  
  37. //creación de un usuario Administrador en System
  38. $userSystem = UserSystem::create([
  39. 'name' => request('name'),
  40. 'email' => request('email'),
  41. 'password' => bcrypt($password)
  42. ]);
  43.  
  44. $personaSystem=PersonaSystem::create([
  45. 'telefono'=> request('telefono'),
  46. 'direccion'=> request('direccion'),
  47. 'user_id' => $userSystem->id,
  48. ]);
  49.  
  50. $administradorSystem=AdministradorSystem::create([
  51. 'user_id' => $userSystem->id,
  52. 'persona_id' => $personaSystem->id,
  53. 'propidad_id'=> request('propiedad_id'),
  54. ]);
  55.  
  56.  
  57.  
  58. //creación de un usuario administrador en el tenant
  59. $userTenant = UserTenant::create([
  60. 'name' => request('name'),
  61. 'email' => request('email'),
  62. 'password' => bcrypt($password)
  63. ]);
  64.  
  65. $personaTenant=PersonaTenant::create([
  66. 'telefono'=> request('telefono'),
  67. 'direccion'=> request('direccion'),
  68. 'user_id' => $userTenant->id,
  69. ]);
  70.  
  71. $administradorTenant=AdministradorTenant::create([
  72. 'user_id' => $userTenant->id,
  73. 'persona_id' => $personaTenant->id,
  74. 'propidad_id'=> request('propiedad_id'),
  75. ]);
  76.  
  77.  
  78. return $this->sendResponse(new AdministradorResource($administrador),'Administrador Creado correctamente');
  79.  
  80.  
  81.  
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement