本文整理匯總了PHP中app\models\Post::leftJoin方法的典型用法代碼示例。如果您正苦於以下問題:PHP Post::leftJoin方法的具體用法?PHP Post::leftJoin怎麽用?PHP Post::leftJoin使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類app\models\Post
的用法示例。
在下文中一共展示了Post::leftJoin方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: posts
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: index
/**
* 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);
}