Пример #1
0
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function show($id)
 {
     //
     $status = Input::get('status');
     if ($status == 'comment') {
         $comment_new = User_App_Comment::join('apps', 'apps.id', '=', 'user__app__comments.a_id')->join('users', 'users.id', '=', 'user__app__comments.u_id')->select('user__app__comments.id', 'users.name as user_name', 'users.id as user_id', 'users.img as user_img', 'apps.id as app_id', 'apps.name as app_name', 'apps.img_url as app_img', 'comment', 'user__app__comments.created_at')->orderBy('user__app__comments.created_at', 'desc')->where('user__app__comments.a_id', '=', $id);
         $return_all = $comment_new->get();
         $empty_test = $comment_new->first();
         if (empty($empty_test)) {
             return Response::json(array('message' => 'No comments', 'status' => 'error'));
         }
         return $return_all;
     }
     $app_detail = App::where('id', '=', $id)->first();
     $app_behaviors = App::join('app__behaviors', 'app__behaviors.a_id', '=', 'apps.id')->join('behaviors', 'behaviors.id', '=', 'app__behaviors.b_id')->where('apps.id', '=', $id)->select('behaviors.id', 'behaviors.name', 'behaviors.genre', 'app__behaviors.score')->orderBy('behaviors.genre', 'asc')->orderBy('behaviors.id', 'asc')->get();
     $app_comments = User_App_Comment::join('apps', 'apps.id', '=', 'user__app__comments.a_id')->join('users', 'users.id', '=', 'user__app__comments.u_id')->where('user__app__comments.a_id', '=', $id)->select('user__app__comments.id', 'users.id as user_id', 'users.name as user_name', 'apps.id as app_id', 'apps.name as app_name', 'apps.img_url as app_img', 'comment', 'user__app__comments.created_at as comment_time')->orderBy('user__app__comments.created_at', 'desc')->get();
     $app_favorite_counts = App::join('user__app__favorite', 'user__app__favorite.a_id', '=', 'apps.id')->where('apps.id', '=', $id)->count();
     $app_comment_counts = App::join('user__app__comments', 'user__app__comments.a_id', '=', 'apps.id')->where('apps.id', '=', $id)->count();
     $app_clusters = Cluster::join('apps', 'apps.cl_id', '=', 'clusters.id')->where('apps.id', '!=', $id)->where('clusters.id', '=', $app_detail['cl_id'])->get();
     $app_detail->behaviors = $app_behaviors;
     $app_detail->comments = $app_comments;
     $app_detail->favorite_count = $app_favorite_counts;
     $app_detail->comment_count = $app_comment_counts;
     $app_detail->group_app = $app_clusters;
     if (Auth::check()) {
         $user_id = Auth::user()->id;
         $check_suck = User::join('user__app__favorite', 'user__app__favorite.u_id', '=', 'users.id')->where('user__app__favorite.a_id', '=', $id)->where('user__app__favorite.u_id', '=', $user_id)->first();
         if (empty($check_suck)) {
             $user_favorite = "Not yet";
         } else {
             $user_favorite = "Already";
         }
     } else {
         $user_favorite = "Not login";
     }
     $app_detail->user_favorite = $user_favorite;
     $app_detail->success = 'success';
     return $app_detail;
 }
 private function unfoldFavorInfo($favor)
 {
     $author = User::find($favor->author_id);
     if ($author) {
         $favor->author = array_only($author->toArray(), ['id', 'name', 'avatar_url']);
     }
     $app = App::where('client_id', $favor->app_id)->first();
     if ($app) {
         $favor->app = array_only($app->toArray(), ['client_id', 'name', 'logo_url', 'homepage_url']);
     }
     return $favor;
 }
 public function getAuthClient()
 {
     $clientId = Authorizer::getClientId();
     $app = App::where('client_id', $clientId)->first();
     return response()->json($app);
 }
 /**
  * Index.
  *
  * @param Request $request request object
  *
  * @return Array
  */
 public function index(Request $request)
 {
     $app = App::where('client_id', 'koala')->first();
     return redirect($app->homepage_url);
 }
 private function unfoldMessageInfo($message)
 {
     $onlyNeedFeilds = ['id', 'name', 'avatar_url'];
     $app = App::where('client_id', $message->app_id)->first();
     if ($app) {
         $message->app = array_only($app->toArray(), ['client_id', 'name', 'logo_url', 'homepage_url']);
     }
     $author = User::find($message->author_id);
     if ($author) {
         $message->author = array_only($author->toArray(), $onlyNeedFeilds);
     }
     $receiver = User::find($message->receiver_id);
     if ($receiver) {
         $message->receiver = array_only($receiver->toArray(), $onlyNeedFeilds);
     }
     $allReceiverIds = [];
     if (!empty($message->all_receiver_ids)) {
         $allReceiverIds = explode(',', $message->all_receiver_ids);
     }
     $all_receivers = [];
     foreach ($allReceiverIds as $receiverId) {
         $user = User::find($receiverId);
         if ($user) {
             array_push($all_receivers, array_only($user->toArray(), $onlyNeedFeilds));
         }
     }
     $message->all_receivers = $all_receivers;
     return $message;
 }
 public function destroy($id)
 {
     $app = App::where('client_id', $id)->first();
     if (!$app) {
         return response()->json(['error' => '资源不存在'], 404);
     }
     $client = OAuthClient::find($app->client_id);
     if ($client) {
         $client->delete();
     }
     $endpoint = OAuthClientEndPoint::find($app->client_id);
     if ($endpoint) {
         $endpoint->delete();
     }
     OAuthClientScope::where('client_id', $app->client_id)->delete();
     $app->delete();
     return response('', 204);
 }