public function ajax_meal(Request $request) { if ($request->ajax()) { $now = Carbon::now(); $now = $now->toDateString(); $day = $request->input('day'); $year = $request->input('year'); $month = $request->input('month'); $selected_date = Carbon::create($year, $month, $day); $date = $selected_date; $user_id = Auth::user()->id; $meals_with_totals = Meal::getMealsWithTotals($date->toDateString(), $user_id); extract($meals_with_totals); // thsi will create $meals, $meals_planed and $totals and $totals_planned $bmr = Auth::user()->getUserBmr(); $training_done = Training::getTrainingsForDate($selected_date); $meals = $meals_with_totals["meals"]; $returnHTML = view('meals.ajax_meal')->with(compact(array('meals', 'meals_planed', 'title', 'date', 'totals', 'totals_planed', 'now', 'training_done', 'bmr')))->render(); return response()->json(array('success' => true, 'html' => $returnHTML)); } else { echo 'Error'; } }
/** * Display a listing of the resource. * * @return Response */ public function index() { $date = new Carbon(); $training_done = Training::getTrainingsForDate($date); return view('trainings.index')->with('training_done', $training_done); }