public function addWorkouts($workouts) { foreach ($workouts as $workout) { $workout_id = Workout::where('name', $workout[0])->first(); $this->workouts()->attach($workout_id, ['position' => $workout[1]]); } }
/** * Grab the correct individual workout (lift) to display to the user. * * @param Workout $workout * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View */ public function show($user, $name) { $user = \App\User::where(['name' => $user])->get()->first(); $userName = \Auth::user()->id; $lift = \App\Workout::where(['name' => $name])->get()->first(); $liftCollection = \App\Workout::where(['user_id' => $userName])->get(); $weight = \Auth::user()->weights()->get()->last(); $userWeight = \App\Weight::where(['user_id' => \Auth::user()->id])->get()->last(); return view('workouts/show', compact('lift', 'user', 'liftCollection', 'weight', 'userWeight')); }
public function deleteWorkout($id) { $workout = Workout::find($id); $workout->exercises()->detach(); try { $test = Workout::where("id", "=", $id)->delete(); } catch (Exception $e) { error_log($e, 0); } return Response::json($test); }
/** * Run the database seeds. * * @return void */ public function run() { Model::unguard(); // $this->call(UserTableSeeder::class); Model::reguard(); $userTest = User::create(['name' => 'userTest', 'email' => '*****@*****.**', 'password' => bcrypt('userTest'), 'height_inches' => 70]); $workout1 = Workout::create(['user_id' => $userTest->id, 'title' => 'Push', 'note' => 'This is a note']); $workout2 = Workout::create(['user_id' => $userTest->id, 'title' => 'Pull', 'note' => 'This is a note']); $workout3 = Workout::create(['user_id' => $userTest->id, 'title' => 'Legs', 'note' => 'This is a note']); $exercise1 = Exercise::create(['user_id' => $userTest->id, 'title' => 'Barbell Bench Press', 'max_one_rep_max' => 190, 'type' => 'Weighted', 'category' => 'Chest']); $exercise2 = Exercise::create(['user_id' => $userTest->id, 'title' => 'Overhead Press', 'max_one_rep_max' => 100, 'type' => 'Weighted', 'category' => 'Shoulders']); $exercise3 = Exercise::create(['user_id' => $userTest->id, 'title' => 'One Arm Row', 'max_one_rep_max' => 75, 'type' => 'Weighted', 'category' => 'Back']); $exercise4 = Exercise::create(['user_id' => $userTest->id, 'title' => 'Pulldown', 'max_one_rep_max' => 200, 'type' => 'Weighted', 'category' => 'Back']); $exercise5 = Exercise::create(['user_id' => $userTest->id, 'title' => 'Squats', 'max_one_rep_max' => 225, 'type' => 'Weighted', 'category' => 'Legs']); $exercise6 = Exercise::create(['user_id' => $userTest->id, 'title' => 'Deadlifts', 'max_one_rep_max' => 200, 'type' => 'Weighted', 'category' => 'Legs']); $session1 = Session::create(['user_id' => $userTest->id, 'exercise_id' => $exercise1->id, 'session_date' => Carbon::now()]); $session2 = Session::create(['user_id' => $userTest->id, 'exercise_id' => $exercise2->id, 'session_date' => Carbon::now()]); $session3 = Session::create(['user_id' => $userTest->id, 'exercise_id' => $exercise3->id, 'session_date' => Carbon::now()]); $session4 = Session::create(['user_id' => $userTest->id, 'exercise_id' => $exercise4->id, 'session_date' => Carbon::now()]); $session5 = Session::create(['user_id' => $userTest->id, 'exercise_id' => $exercise5->id, 'session_date' => Carbon::now()]); $session6 = Session::create(['user_id' => $userTest->id, 'exercise_id' => $exercise6->id, 'session_date' => Carbon::now()]); $sessionSet1 = SessionSet::create(['session_id' => $session1->id, 'number_of_reps' => 8, 'weight_lifted' => 180, 'one_rep_max' => 190, 'failed' => false]); $sessionSet2 = SessionSet::create(['session_id' => $session1->id, 'number_of_reps' => 8, 'weight_lifted' => 180, 'one_rep_max' => 190, 'failed' => false]); $sessionSet3 = SessionSet::create(['session_id' => $session1->id, 'number_of_reps' => 8, 'weight_lifted' => 180, 'one_rep_max' => 190, 'failed' => false]); $sessionSet4 = SessionSet::create(['session_id' => $session2->id, 'number_of_reps' => 8, 'weight_lifted' => 95, 'one_rep_max' => 100, 'failed' => false]); $sessionSet5 = SessionSet::create(['session_id' => $session2->id, 'number_of_reps' => 8, 'weight_lifted' => 95, 'one_rep_max' => 100, 'failed' => false]); $sessionSet6 = SessionSet::create(['session_id' => $session2->id, 'number_of_reps' => 8, 'weight_lifted' => 95, 'one_rep_max' => 100, 'failed' => false]); $sessionSet7 = SessionSet::create(['session_id' => $session3->id, 'number_of_reps' => 8, 'weight_lifted' => 65, 'one_rep_max' => 80, 'failed' => false]); $sessionSet8 = SessionSet::create(['session_id' => $session3->id, 'number_of_reps' => 8, 'weight_lifted' => 65, 'one_rep_max' => 80, 'failed' => false]); $sessionSet9 = SessionSet::create(['session_id' => $session3->id, 'number_of_reps' => 8, 'weight_lifted' => 65, 'one_rep_max' => 80, 'failed' => false]); $sessionSet10 = SessionSet::create(['session_id' => $session4->id, 'number_of_reps' => 8, 'weight_lifted' => 180, 'one_rep_max' => 190, 'failed' => false]); $sessionSet11 = SessionSet::create(['session_id' => $session4->id, 'number_of_reps' => 8, 'weight_lifted' => 180, 'one_rep_max' => 190, 'failed' => false]); $sessionSet12 = SessionSet::create(['session_id' => $session4->id, 'number_of_reps' => 8, 'weight_lifted' => 180, 'one_rep_max' => 190, 'failed' => false]); $sessionSet13 = SessionSet::create(['session_id' => $session5->id, 'number_of_reps' => 8, 'weight_lifted' => 180, 'one_rep_max' => 190, 'failed' => false]); $sessionSet14 = SessionSet::create(['session_id' => $session5->id, 'number_of_reps' => 8, 'weight_lifted' => 180, 'one_rep_max' => 190, 'failed' => false]); $sessionSet15 = SessionSet::create(['session_id' => $session5->id, 'number_of_reps' => 8, 'weight_lifted' => 180, 'one_rep_max' => 190, 'failed' => false]); $sessionSet16 = SessionSet::create(['session_id' => $session6->id, 'number_of_reps' => 8, 'weight_lifted' => 180, 'one_rep_max' => 190, 'failed' => false]); $sessionSet17 = SessionSet::create(['session_id' => $session6->id, 'number_of_reps' => 8, 'weight_lifted' => 180, 'one_rep_max' => 190, 'failed' => false]); $sessionSet18 = SessionSet::create(['session_id' => $session6->id, 'number_of_reps' => 8, 'weight_lifted' => 180, 'one_rep_max' => 190, 'failed' => false]); $plan1 = Plan::create(['user_id' => $userTest->id, 'title' => '5/3/1', 'start_date' => Carbon::now(), 'end_date' => Carbon::now()->addWeeks(4)]); $planWorkout1 = PlanWorkout::create(['plan_id' => $plan1->id, 'workout_id' => $workout1->id]); $planWorkout2 = PlanWorkout::create(['plan_id' => $plan1->id, 'workout_id' => $workout2->id]); $planWorkout3 = PlanWorkout::create(['plan_id' => $plan1->id, 'workout_id' => $workout3->id]); $planDate1 = PlanDate::create(['plan_workout_id' => $planWorkout1->id, 'planned_date' => Carbon::tomorrow()]); $planDate2 = PlanDate::create(['plan_workout_id' => $planWorkout1->id, 'planned_date' => Carbon::tomorrow()->addDays(5)]); $planDate3 = PlanDate::create(['plan_workout_id' => $planWorkout2->id, 'planned_date' => Carbon::tomorrow()->addDay()]); $planDate4 = PlanDate::create(['plan_workout_id' => $planWorkout2->id, 'planned_date' => Carbon::tomorrow()->addDays(6)]); $planExercise1 = PlanExercise::create(['plan_workout_id' => $planWorkout1->id, 'exercise_id' => $exercise1->id, 'weight_to_add_for_success' => 5, 'weight_to_sub_for_fail' => 5]); $planExercise2 = PlanExercise::create(['plan_workout_id' => $planWorkout1->id, 'exercise_id' => $exercise2->id, 'weight_to_add_for_success' => 5, 'weight_to_sub_for_fail' => 5]); $planSet1 = PlanSet::create(['plan_exercise_id' => $planExercise1->id, 'expected_reps' => 10, 'expected_weight' => 100]); $planSet2 = PlanSet::create(['plan_exercise_id' => $planExercise1->id, 'expected_reps' => 10, 'expected_weight' => 100]); }
/** * Delete the given Workout. * * @param int $id * @return Redirect */ public function getDelete($id = null) { $workout = Workout::destroy($id); // Redirect to the group management page return redirect('admin/workouts')->with('success', Lang::get('message.success.delete')); }
/** * Execute the console command. * * @return mixed */ public function handle() { DB::enableQueryLog(); // Delete all data in the database, TODO: remove before production DB::statement("SET foreign_key_checks=0"); Workout::truncate(); DB::statement("TRUNCATE TABLE `exercise_workout`"); DB::statement("SET foreign_key_checks=1"); // Variable for adding position on exercises in the workout $position = 0; // Workout one $workout = Workout::create(['name' => 'Test workout one']); $exercises = []; $exercises[] = ['Bicep curl', $position++]; $exercises[] = ['Squats', $position++]; $exercises[] = ['Bench press', $position++]; $workout->addExercises($exercises); $position = 0; // Workout two $workout = Workout::create(['name' => 'Test workout two']); $exercises = []; $exercises[] = ['Front squats', $position++]; $exercises[] = ['Squats', $position++]; $exercises[] = ['Bench press', $position++]; $workout->addExercises($exercises); $position = 0; // Workout three $workout = Workout::create(['name' => 'Test workout three']); $exercises = []; $exercises[] = ['Overhead press', $position++]; $exercises[] = ['Squats', $position++]; $exercises[] = ['Skull-crusher', $position++]; $workout->addExercises($exercises); $position = 0; // Workout four $workout = Workout::create(['name' => 'Test workout four']); $exercises = []; $exercises[] = ['Bicep curl', $position++]; $exercises[] = ['Lateral raise', $position++]; $exercises[] = ['Overhead press', $position++]; $workout->addExercises($exercises); $position = 0; // Workout five $workout = Workout::create(['name' => 'Test workout five']); $exercises = []; $exercises[] = ['Pull-up', $position++]; $exercises[] = ['Front Squats', $position++]; $exercises[] = ['Bench press', $position++]; $workout->addExercises($exercises); $position = 0; // Workout six $workout = Workout::create(['name' => 'Test workout six']); $exercises = []; $exercises[] = ['Bicep curl', $position++]; $exercises[] = ['Skull-crusher', $position++]; $exercises[] = ['Lateral raise', $position++]; $workout->addExercises($exercises); $position = 0; }
public function createNewWorkout($id) { $workout = Workout::create(['name' => 'Test']); $workoutPlan = WorkoutPlan::find($id); $workoutPlan->addWorkouts(array($workout->id)); $result = Workout::with('exercises', 'exercises.muscles')->find($workout->id); return Response::json($result); }
public function workouts() { return Workout::select("id", "title")->lists("title", "id"); }