/**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     DB::table('users')->delete();
     $adminRole = Role::whereName('administrator')->first();
     $userRole = Role::whereName('user')->first();
     $user = User::firstOrCreate(['email' => '*****@*****.**']);
     $user->name = 'Jill';
     $user->email = '*****@*****.**';
     $user->password = \Hash::make('helloworld');
     $user->save();
     $user->assignRole($adminRole);
     $profile = new UserProfile();
     $user->profile()->save($profile);
     $user = User::firstOrCreate(['email' => '*****@*****.**']);
     $user->name = 'Jamal';
     $user->email = '*****@*****.**';
     $user->password = \Hash::make('helloworld');
     $user->save();
     $user->assignRole($userRole);
     $profile = new UserProfile();
     $user->profile()->save($profile);
     $user = User::firstOrCreate(['email' => '*****@*****.**']);
     $user->name = 'Kakha Urigashvili';
     $user->email = '*****@*****.**';
     $user->password = \Hash::make('123');
     $user->save();
     $user->assignRole($adminRole);
     $profile = new UserProfile();
     $user->profile()->save($profile);
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $user = User::where('email', '*****@*****.**')->first();
     $routine = Routine::firstOrCreate(['name' => 'Two Foot Jump for Athletes', 'goal_id' => 2, 'frequency_id' => 2, 'difficulty_id' => 2, 'description' => 'This routines aimed to help increase two foot jump. It can be very helpful for basketball and volleyball players. Make sure to focus on executing each jumping exercise with maximum speed and force.', 'created_by_id' => $user->id]);
     RoutineExercise::firstOrCreate(['routine_id' => $routine->id, 'exercise_id' => 4, 'day' => 1, 'order' => 1, 'reps' => 8, 'sets' => 4, 'rest' => 120]);
     RoutineExercise::firstOrCreate(['routine_id' => $routine->id, 'exercise_id' => 8, 'day' => 1, 'order' => 2, 'reps' => 6, 'sets' => 3, 'rest' => 60]);
     RoutineExercise::firstOrCreate(['routine_id' => $routine->id, 'exercise_id' => 5, 'day' => 2, 'order' => 1, 'reps' => 8, 'sets' => 4, 'rest' => 120]);
     RoutineExercise::firstOrCreate(['routine_id' => $routine->id, 'exercise_id' => 9, 'day' => 2, 'order' => 2, 'reps' => 4, 'sets' => 4, 'rest' => 120]);
     $routine = Routine::firstOrCreate(['name' => 'Bigger Arms', 'goal_id' => 4, 'frequency_id' => 1, 'difficulty_id' => 1, 'description' => 'This routines aimed to help increase upper body muscle size and tone. Make sure perform each exercise in control fashion.', 'created_by_id' => $user->id]);
     RoutineExercise::firstOrCreate(['routine_id' => $routine->id, 'exercise_id' => 1, 'day' => 1, 'order' => 1, 'reps' => 12, 'sets' => 4, 'rest' => 90]);
     RoutineExercise::firstOrCreate(['routine_id' => $routine->id, 'exercise_id' => 2, 'day' => 1, 'order' => 2, 'reps' => 10, 'sets' => 4, 'rest' => 90]);
     RoutineExercise::firstOrCreate(['routine_id' => $routine->id, 'exercise_id' => 3, 'day' => 1, 'order' => 3, 'reps' => 10, 'sets' => 4, 'rest' => 90]);
     RoutineExercise::firstOrCreate(['routine_id' => $routine->id, 'exercise_id' => 7, 'day' => 1, 'order' => 4, 'reps' => 12, 'sets' => 3, 'rest' => 90]);
 }
 /**
  * Responds to requests to GET /profile
  */
 public function getEdit()
 {
     $current_user = Auth::user();
     $user = User::with('profile')->find($current_user->id);
     return view('profile.edit', ['user' => $user]);
 }
 public function getSocialHandle($provider)
 {
     $user = Socialite::driver($provider)->user();
     $code = Input::get('code');
     if (!$code) {
         return view('auth.login')->with('flash_message', 'You did not share your profile data with the social app.');
     }
     if (!$user->email) {
         return view('auth.login')->with('flash_message', 'You did not share your email with the social app.');
     }
     $socialUser = null;
     //Check is this email present
     $userCheck = User::where('email', '=', $user->email)->first();
     if (!empty($userCheck)) {
         $socialUser = $userCheck;
     } else {
         $sameSocialId = Social::where('social_id', '=', $user->id)->where('provider', '=', $provider)->first();
         if (empty($sameSocialId)) {
             //There is no combination of this social id and provider, so create new one
             $newSocialUser = new User();
             $newSocialUser->email = $user->email;
             $newSocialUser->name = $user->name;
             $newSocialUser->save();
             $newSocialUser->assignDefaultRole();
             $socialData = new Social();
             $socialData->social_id = $user->id;
             $socialData->provider = $provider;
             $newSocialUser->social()->save($socialData);
             $socialUser = $newSocialUser;
         } else {
             //Load this existing social user
             $socialUser = $sameSocialId->user;
         }
     }
     Auth::login($socialUser, true);
     $user = Auth::user();
     $data = array('user' => $user);
     Mail::send('auth.emails.register-thank-you', $data, function ($message) use($user) {
         $recipient_email = $user->email;
         $recipient_name = $user->name;
         $subject = 'Welcome to Fitness Base!';
         $message->to($recipient_email, $recipient_name)->subject($subject);
     });
     if (Auth::user()->hasRole('user')) {
         return redirect('exercises');
     }
     if (Auth::user()->hasRole('administrator')) {
         return redirect('exercises');
     }
     return \App::abort(500);
 }