本文整理匯總了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]);
}