Exemplo n.º 1
0
 public function crear(Request $request)
 {
     if ($request->ajax()) {
         $name = $request['name'];
         $email = $request['email'];
         $password = $request['password'];
         if ($request['admin'] == 1) {
             $admin = 1;
         } else {
             $admin = 0;
         }
         $aux = \App\User::find($email);
         if ($aux == null) {
             $subdistri = \App\Subdistribuidor::find($name);
             if ($subdistri == null) {
                 try {
                     \App\User::create(['name' => $name, 'email' => $email, 'isAdmin' => $admin, 'password' => bcrypt('password')]);
                     \App\Subdistribuidor::create(['cedula' => '-', 'nombre' => $name, 'telefono' => '-', 'email' => '-', 'emailDistribuidor' => $email]);
                     return 1;
                 } catch (Exception $e) {
                     return $e;
                 }
             } else {
                 return -2;
             }
         } else {
             return -1;
         }
     }
 }
 public function crear(Request $request)
 {
     if ($request->ajax()) {
         try {
             $subdistribuidor = \App\Subdistribuidor::find($request['nombre']);
             $email = \DB::select("select * from users where users.name = ?", [$request['distribuidor']]);
             if ($subdistribuidor == null) {
                 \App\Subdistribuidor::create(['nombre' => $request['nombre'], 'emailDistribuidor' => $email[0]->email, 'cedula' => null, 'telefono' => null, 'email' => null]);
                 return 1;
             } else {
                 return -1;
             }
         } catch (Exception $e) {
             return $e->getMessage();
         }
     }
 }