本文整理汇总了PHP中app\models\Article::whereRaw方法的典型用法代码示例。如果您正苦于以下问题:PHP Article::whereRaw方法的具体用法?PHP Article::whereRaw怎么用?PHP Article::whereRaw使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\Article
的用法示例。
在下文中一共展示了Article::whereRaw方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: feed
/**
* Список новостей
* @param Request $request
* @param null $alias
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function feed(Request $request, $alias = null)
{
$page = Paginator::resolveCurrentPage('page');
$per_page = config('paginator.per_page');
$category = Category::where('alias', $alias)->first();
$order_by = $request->input('order_by');
$articles = Article::whereRaw('1=1');
switch ($order_by) {
case 'name_desc':
$articles->orderBy('name', 'desc');
break;
case 'name_asc':
$articles->orderBy('name', 'asc');
break;
case 'date_desc':
$articles->orderBy('created_at', 'desc');
break;
case 'date_asc':
$articles->orderBy('created_at', 'asc');
break;
default:
$articles->orderBy('created_at', 'desc');
break;
}
if (is_null($category)) {
$articles = $articles->paginate($per_page);
} else {
$articles = $articles->where('category_id', $category->id)->paginate($per_page);
}
if ($order_by) {
$articles->appends('order_by', $order_by);
}
return view('pages/feed', ['articles' => $articles, 'category' => $category, 'page' => $page, 'order_by' => $order_by]);
}