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); }