/** * share a post to Activity feed, handles POST request. * * @param object $request * * * @return json */ public function sharedStatus(Request $request) { try { $post = new activitypost(); $post->email = $request->email; $post->userId = $request->userId; $post->firstname = $request->firstName; $post->username = $request->userName; $post->type = 'shared'; $post->post_id = $request->postId; $post->post_text = $request->status; if ($posts = $post->save()) { return response()->json(['posts' => $posts, 'status' => 201], 201); } else { return response()->json(['status' => 404], 404); } } catch (Illuminate\Database\QueryException $e) { return response()->json(['status' => 505], 505); } }
/** * Fetch images of a user profile. * * @param object $request * * * @return json */ public function photos(Request $request) { $username = $request->username; try { $userId = User::where('username', $username)->get()[0]->id; $userPosts = activitypost::where('userid', $userId)->get(); $photos = []; foreach ($userPosts as $post) { if ($post->attachment != 'None') { array_push($photos, $post->attachment); } } return response()->json(['status' => 200, 'photos' => $photos], 200); } catch (Illuminate\Database\QueryException $e) { return response()->json(['status' => 200], 200); } }