本文整理匯總了PHP中app\models\Article::raw方法的典型用法代碼示例。如果您正苦於以下問題:PHP Article::raw方法的具體用法?PHP Article::raw怎麽用?PHP Article::raw使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類app\models\Article
的用法示例。
在下文中一共展示了Article::raw方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: use
function article_per_author()
{
///////////
// Query //
///////////
$query[] = ['$match' => ['published_at' => ['$lte' => \Carbon\Carbon::now()->format('Y-m-d')]]];
$query[] = ['$group' => ['_id' => '$user_id', 'last_created_at' => ['$first' => '$created_at'], 'last_published_at' => ['$first' => '$published_at'], 'count' => ['$sum' => 1]]];
//////////////////////////////
// Get Result //
//////////////////////////////
$data = [];
$total_article = Article::raw(function ($collection) use($query) {
return $collection->aggregate($query);
});
foreach ($total_article as $key => $value) {
$new = User::find($value['_id']);
if ($new) {
$new['total_article'] = $value['count'];
$new['last_created_at'] = $value['last_created_at'];
$new['last_published_at'] = $value['last_published_at'];
$data[] = $new->toArray();
}
}
return response()->json(JSend::success(['count' => count($data), 'data' => $data])->asArray())->setCallback($this->request->input('callback'));
}