/** * Get the validation rules that apply to the request. * * @return array */ public function rules() { $types = \App\Models\BodyMeasurementType::orderBy('id')->get(); $minTypeID = $types->first()->id; $maxTypeID = $types->last()->id; $unitIDs = \App\Models\Unit::validationIDs($types->find($this->request->get('body_measurement_type_id'))->unit_type); return ['body_measurement_type_id' => sprintf('required|integer|min:%d|max:%d', $minTypeID, $maxTypeID), 'value' => 'required|numeric|min:0', 'unit_id' => sprintf('required|integer|in:%s', $unitIDs)]; }
/** * Responds to GET::/user/goals/edit. * * @return body.edit_goal view with a prepopulated form for editing a goal. */ public function getEdit($goalID) { $goal = \App\Models\Goal::find($goalID); if ($goal && $goal->user_id == \Auth::User()->id) { $types = \App\Models\BodyMeasurementType::lists('name', 'id'); $units = \App\Models\Unit::lists('abbreviation', 'id'); return view('body.edit_goal')->with('types', $types)->with('goal', $goal)->with('units', $units); } else { \Session::flash('goal_update_error', 'You are not authorized to update this goal'); return redirect('/goals'); } }
/** * Responds to GET::/measurements/edit/{measurementID}. Returns the edit page * with existing measurement values already filled in. * * @param int $id The id of the measurement to edit. * @return body.edit_measurement view with measuremenet values already filled in */ public function getEdit($id) { $measurement = \App\Models\BodyMeasurement::find($id); if ($measurement && \Auth::User()->id == $measurement->user_id) { $types = \App\Models\BodyMeasurementType::lists('name', 'id'); $units = \App\Models\Unit::lists('abbreviation', 'id'); return view('body.edit_measurement')->with('measurement', $measurement)->with('types', $types)->with('units', $units); } else { \Session::flash('mesaurement_update_error', 'You are not authorized to edit this measurement'); return redirect('/measurements'); } }
/** * Run the database seeds. * * @return void */ public function run() { DB::table('goals')->insert(['created_at' => Carbon\Carbon::now()->toDateTimeString(), 'updated_at' => Carbon\Carbon::now()->toDateTimeString(), 'name' => 'Gain Weight', 'user_id' => 1, 'body_measurement_type_id' => BodyMeasurementType::where('name', 'Weight')->first()->id, 'unit_id' => Unit::where('name', 'pound')->first()->id, 'value' => 90.90900000000001]); }