private function showText($request) { $texts = Text::with('user', 'question')->where('question_id', $request->question_id)->get(['created_at', 'user_id', 'description', 'question_id']); foreach ($texts as $text) { $text['date'] = Date::parse($text->created_at)->diffForHumans(); } return ['text' => $texts]; }
private function reloadQuestions($id) { $questions = Question::where('product_id', $id)->orderBy('created_at', 'DESC')->get(); foreach ($questions as $question) { $question['texts'] = Text::with('user')->where('question_id', $question->id)->get(); foreach ($question->texts as $text) { $text['date'] = Date::parse($text->created_at)->diffForHumans(); } } return $questions; }