/** * Run the database seeds. * * @return void */ public function run() { Days::create(['id' => '1', 'day' => 'Sunday', 'description' => 'days of the week']); Days::create(['id' => '2', 'day' => 'Monday', 'description' => 'days of the week']); Days::create(['id' => '3', 'day' => 'Teusday', 'description' => 'days of the week']); Days::create(['id' => '4', 'day' => 'Wednesday', 'description' => 'days of the week']); Days::create(['id' => '5', 'day' => 'Thursday', 'description' => 'days of the week']); }
public function todaysmacros() { $token = (string) JWTAuth::getToken(); $user = JWTAuth::toUser($token); $data = json_decode($_POST["json"]); $todaydate = $_POST["todaydate"]; $jsDateTS = strtotime($todaydate); $todaydate = date('Y-m-d', $jsDateTS); $todaydate = $todaydate . " 00:00:00"; $dataObj = []; $dataObj["protlimit"] = 0; $dataObj["kclimit"] = 0; $dataObj["fatlimit"] = 0; $dataObj["carblimit"] = 0; $totalfats = 0; $totalcarbs = 0; $totalprot = 0; $totalkcals = 0; if ($todaydate == "") { $todaydate = date(); } $currentmacro = Macros::where('current', 1)->where('user_id', $user->id)->first(); if ($currentmacro !== null) { $startdate = $currentmacro->startdate; $day = Days::where('date', '=', $todaydate)->where('macro_id', $currentmacro->id)->first(); if ($day !== null) { // add up totals for todays macros // add up usage for today $day_id = $day->id; $mymeals = Daymeals::where('day_id', $day_id)->get(); if ($day->type == "workout") { $dataObj["protlimit"] = $currentmacro->wprot; $dataObj["kclimit"] = $currentmacro->wkcals; $dataObj["fatlimit"] = $currentmacro->wfats; $dataObj["carblimit"] = $currentmacro->wcarbs; } if ($day->type == "rest") { $dataObj["protlimit"] = $currentmacro->prot; $dataObj["kclimit"] = $currentmacro->kcals; $dataObj["fatlimit"] = $currentmacro->fats; $dataObj["carblimit"] = $currentmacro->carbs; } foreach ($mymeals as $mymeal) { $thismeal = Meals::where('id', $mymeal->meal_id)->first(); $totalfats = $totalfats + $thismeal->fats; $totalcarbs = $totalcarbs + $thismeal->carbs; $totalprot = $totalprot + $thismeal->prot; $totalkcals = $totalkcals + $thismeal->kcals; } } else { //$dataObj = []; } $dataObj["protsofar"] = $totalprot; $dataObj["kcsofar"] = $totalkcals; $dataObj["fatsofar"] = $totalfats; $dataObj["carbsofar"] = $totalcarbs; $dataObj["thedate"] = $todaydate; $dataObj["extra"] = ""; } else { //$dataObj="nope nothing"; } return ['data' => ['dataitem' => $dataObj]]; }