コード例 #1
0
ファイル: PostController.php プロジェクト: QiuCarson/doc
 public function posts(Request $request)
 {
     $id = $request->input('id');
     if ($id < 1) {
         return response()->json(['status' => false, 'message' => '参数有错误']);
         exit;
     }
     $posts = Post::leftJoin('websites', 'posts.website', '=', 'websites.websites_id')->leftJoin('projects', 'posts.project', '=', 'projects.projects_id')->where('posts_id', $id)->first();
     return response()->json($posts);
 }
コード例 #2
0
ファイル: PostController.php プロジェクト: QiuCarson/doc
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index($current_page)
 {
     $current_page = $current_page ? $current_page : 1;
     $current_page = $current_page - 1;
     $page = 10;
     //echo $current_page*$page;exit;
     $post = Post::leftJoin('websites', 'posts.website', '=', 'websites.websites_id')->leftJoin('projects', 'posts.project', '=', 'projects.projects_id')->orderby('posts_id', 'desc')->offset($current_page * $page)->limit($page);
     $posts['data'] = $post->get();
     $posts['count'] = Post::count();
     $posts['pageSize'] = $page;
     return response()->json($posts);
 }