public function index(Request $request) { $projectId = $request->get('projectId'); if (!is_numeric($projectId)) { throw new \Exception('Invalid project id passed'); } $allComments = ProjectComment::where('project_id', $projectId)->where('status', true)->with(['user' => function ($query) { $query->select(['id', 'name']); }])->get(); $formattedComments = []; foreach ($allComments as $comment) { $formattedComments[] = ['id' => $comment->id, 'userName' => isset($comment->user->name) ? $comment->user->name : 'Unknown', 'comment' => strip_tags($comment->comment), 'userId' => isset($comment->user->id) ? $comment->user->id : 0, 'projectId' => $comment->project_id, 'date' => $comment->created_at->toDateTimeString()]; } return response()->json($formattedComments); }
function getBlockpost() { $startDate = date("Y-m-d H:i:s"); $endDate = date("Y-m-d H:i:s", strtotime('-24 hours')); $unsafeDetails = Unsafe::where('notified', '1')->where('status', '1')->where('updated_at', '>=', $endDate)->get(); //dd($unsafeDetails); for ($i = 0; $i < count($unsafeDetails); $i++) { $id = $unsafeDetails[$i]['id']; $type = $unsafeDetails[$i]['type']; $post_id = $unsafeDetails[$i]['post_id']; $user_id = $unsafeDetails[$i]['user_id']; if ($type == "comments") { $blockComment = ProjectComment::where('id', '=', $post_id)->where('user_id', $user_id)->update(array('status' => '2')); } if ($type == "updates") { $blockUpdate = ProjectUpdates::where('id', '=', $post_id)->where('user_id', $user_id)->update(array('status' => '2')); } $update = Unsafe::where('id', '=', $id)->update(array('notified' => '4')); } }