【发布时间】:2019-10-28 01:31:44
【问题描述】:
如何使用 Laravel fluent 查询构建器获取行数
我已附加用于过滤其他数据的查询,并且我还需要获取行数。
这是数据库表:-
$results = DB::table('newsfeed_posts')
->select('newsfeed_posts.*', 'users.first_name as posted_user_first_name', 'users.last_name as posted_user_last_name', 'users.profile_image as posted_user_profile_image','proid.profile_image as posted_receiver_profile_image', 'timeline.first_name as post_receiver_first_name', 'timeline.last_name as post_receiver_last_name', 'timeline.office_branch_id as post_receiver_office_id')
->leftJoin('users', 'users.id', 'newsfeed_posts.post_sender_id')
->leftJoin('users as timeline', 'timeline.id', 'newsfeed_posts.post_receiver_id')
->leftJoin('users as proid', 'proid.id', 'newsfeed_posts.post_receiver_id')
->where('newsfeed_posts.deleted_status', '0')
// ->where('newsfeed_posts.post_sender_id', Auth::user()->id)
->where('newsfeed_posts.post_receiver_id', Auth::user()->id)
->groupBy('newsfeed_posts.id')
->orderBy('newsfeed_posts.id', 'DESC')
->get();
return $results;
【问题讨论】:
-
$results是一个集合,因此请随时使用$results->count();。 laravel.com/docs/5.8/collections#method-count