function newUserAdmin(Request $request)
 {
     $inputs = $request->all();
     $files = $request->file();
     $fileName = str_random(40) . '**' . $request->file('photo')->getClientOriginalName();
     $request->file('photo')->move(base_path() . '/public/uploads/users/', $fileName);
     $inputs['photo'] = $fileName;
     $user = User::create($inputs);
     if ($inputs['role_id'] == 5) {
         $agent = Agent::where('user_id', $inputs['agent'])->first();
         $agent['user_id'] = $user->id;
         $agent->save();
     }
     return redirect()->back()->with('messageSuccess', 1);
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     User::create(['name' => 'Juan', 'email' => '*****@*****.**', 'username' => 'juan2ramos', 'last_name' => 'Ramos', 'mobile_phone' => '', 'phone' => '', 'photo' => '', 'role_id' => '1', 'password' => bcrypt('12345')]);
     User::create(['name' => 'Ximena', 'email' => '*****@*****.**', 'username' => 'ximena', 'last_name' => 'Gomez', 'mobile_phone' => '', 'phone' => '', 'photo' => '', 'role_id' => '1', 'password' => bcrypt('12345')]);
     User::create(['name' => 'miller', 'email' => '*****@*****.**', 'username' => 'miller', 'last_name' => 'preciado', 'mobile_phone' => '', 'phone' => '', 'photo' => '', 'role_id' => '1', 'password' => bcrypt('12345')]);
     User::create(['name' => 'Alejandra', 'email' => '*****@*****.**', 'username' => 'Alejandra', 'last_name' => 'Betancur', 'mobile_phone' => '', 'phone' => '', 'photo' => '', 'role_id' => '1', 'password' => bcrypt('12345')]);
     /******************** Super Administrator **********************/
     User::create(['name' => 'Santiago', 'email' => '*****@*****.**', 'username' => 'santo52', 'last_name' => 'Ruiz', 'mobile_phone' => '', 'phone' => '', 'photo' => '', 'role_id' => '1', 'password' => bcrypt('12345')]);
     /******************** Administrator **********************/
     User::create(['name' => 'administrador', 'email' => '*****@*****.**', 'username' => 'administrador', 'last_name' => '', 'mobile_phone' => '', 'phone' => '', 'photo' => '', 'role_id' => '2', 'password' => bcrypt('12345')]);
     /******************** Customer **********************/
     User::create(['name' => 'Cliente', 'email' => '*****@*****.**', 'username' => 'cliente', 'last_name' => '', 'mobile_phone' => '', 'phone' => '', 'photo' => '', 'role_id' => '4', 'password' => bcrypt('12345')]);
     /******************** Agents *************************/
     $user1 = User::create(['name' => 'Agent1', 'email' => '*****@*****.**', 'username' => 'Agent One', 'last_name' => '', 'mobile_phone' => '', 'phone' => '', 'photo' => '', 'role_id' => '5', 'password' => bcrypt('12345')]);
     Agent::create(['user_id' => $user1->id]);
     $user2 = User::create(['name' => 'Agent2', 'email' => '*****@*****.**', 'username' => 'Agent Two', 'last_name' => '', 'mobile_phone' => '', 'phone' => '', 'photo' => '', 'role_id' => '5', 'password' => bcrypt('12345')]);
     Agent::create(['user_id' => $user2->id]);
     $user3 = User::create(['name' => 'Agent3', 'email' => '*****@*****.**', 'username' => 'Agent Three', 'last_name' => '', 'mobile_phone' => '', 'phone' => '', 'photo' => '', 'role_id' => '5', 'password' => bcrypt('12345')]);
     Agent::create(['user_id' => $user3->id]);
     $user4 = User::create(['name' => 'Agent4', 'email' => '*****@*****.**', 'username' => 'Agent Four', 'last_name' => '', 'mobile_phone' => '', 'phone' => '', 'photo' => '', 'role_id' => '5', 'password' => bcrypt('12345')]);
     Agent::create(['user_id' => $user4->id]);
     $user5 = User::create(['name' => 'Agent5', 'email' => '*****@*****.**', 'username' => 'Agent Five', 'last_name' => '', 'mobile_phone' => '', 'phone' => '', 'photo' => '', 'role_id' => '5', 'password' => bcrypt('12345')]);
     Agent::create(['user_id' => $user5->id]);
 }
 public function postRegister(Request $request)
 {
     $validator = $this->validator($request->all());
     if ($validator->fails()) {
         $this->throwValidationException($request, $validator);
     }
     $user = $this->create($request->all());
     if ($user->role_id == 3) {
         $agent = Agent::with('providers')->get()->sortBy(function ($agent) {
             return $agent->providers()->count();
         })->first();
         $provider = new Provider();
         $provider->agent_id = $agent->id;
         $provider->user_id = $user->id;
         $provider->save();
         Notification::create(['user_id' => $agent->user_id, 'text' => 'Se ha registrado un proveedor', 'url' => route('searchProvider')]);
     } else {
         Mail::send('emails.welcome', ['user' => $user], function ($m) use($user) {
             $m->to($user->email, $user->name)->subject('Bienvenido a Agrosellers!');
         });
     }
     auth()->loginUsingId($user->id);
     return redirect($this->redirectPath());
 }