hasOne(Point::class, 'id', 'last_child_review_point_id'); } public function lastChildReviewNote() { return $this->hasOne(Note::class, 'id', 'last_child_review_point_scoped_note_id'); } public function lastChildPlan() { return $this->hasOne(Point::class, 'id', 'last_child_review_point_id'); } public function lastChildPlanNote() { return $this->hasOne(Note::class, 'id', 'last_child_plan_point_scoped_note_id'); } public static function getIntakePointsOfCategory(Client $_patient, String $_category, Note $_note) { $points = Point ::where('client_id', $_patient->id) ->where('category', $_category) ->where('addition_reason_category', 'ON_INTAKE') ->where(function ($query1) use ($_note) { $query1 ->where('is_removed', false) ->orWhere(function ($query2) use ($_note) { $query2->where('is_removed', true) ->where('removed_in_note_id', $_note->id); }); }) ->orderBy('created_at') ->get(); foreach ($points as $point) { if ($point->data) { $point->data = json_decode($point->data); } } return $points; } }