本文整理汇总了PHP中app\Posts::getPostByCategory方法的典型用法代码示例。如果您正苦于以下问题:PHP Posts::getPostByCategory方法的具体用法?PHP Posts::getPostByCategory怎么用?PHP Posts::getPostByCategory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\Posts
的用法示例。
在下文中一共展示了Posts::getPostByCategory方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: index
/**
* Show the application dashboard to the user.
*
* @return Response
*/
public function index()
{
$posts = \App\Posts::where('id', '>', 0)->orderBy("created_at", "desc")->get();
$search_info = "";
if (isset($_GET['user'])) {
$search_info = "You are viewing all posts by " . \App\User::find($_GET['user'])->name;
$posts = \App\Posts::where('user_id', '=', $_GET['user'])->orderBy("created_at", "desc")->get();
}
if (isset($_GET['category'])) {
$search_info = "You are viewing all posts in " . \App\categories::find($_GET['category'])->name;
$posts = \App\Posts::getPostByCategory($_GET['category']);
}
if (isset($_GET['search'])) {
$posts = \App\Posts::where('info', 'like', $_GET['search'] . '%')->orWhere('title', 'like', $_GET['search'] . '%')->orWhere('link', 'like', $_GET['search'] . '%')->orderBy('created_at', 'desc')->get();
$search_info = "Your search returned " . $posts->count() . " Results";
}
$data = array('posts' => $posts, 'search_info' => $search_info, 'users' => \App\User::get());
return view('home')->with($data);
}