本文整理汇总了PHP中app\News::published方法的典型用法代码示例。如果您正苦于以下问题:PHP News::published方法的具体用法?PHP News::published怎么用?PHP News::published使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\News
的用法示例。
在下文中一共展示了News::published方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: search
public function search(Request $request)
{
$search = $request->search;
$str = str_replace(' ', '_', $search);
$users = [];
if (!is_numeric($str)) {
$users = User::where('level_id', '>', 2)->where('banned', 0)->where('slug', 'LIKE', '%' . $str . '%')->with('articles')->get();
}
if (Auth::check() && Auth::user()->level_id > 3) {
$news = News::where('title', 'LIKE', '%' . $str . '%')->get();
} else {
$news = News::published()->where('title', 'LIKE', '%' . $str . '%')->get();
}
return view('news.search', compact('users', 'news', 'search'));
}
示例2: boot
/**
* Define your route model bindings, pattern filters, etc.
*
* @param \Illuminate\Routing\Router $router
* @return void
*/
public function boot(Router $router)
{
parent::boot($router);
$router->bind('articles', function ($slug) {
return \Route::currentRouteName() == "articles.edit" ? \App\Article::findOrFail($slug) : \App\Article::published()->findOrFail($slug);
});
$router->bind('news', function ($id) {
return \Route::currentRouteName() == "news.edit" ? \App\News::findOrFail($id) : \App\News::published()->findOrFail($id);
});
$router->bind('tags', function ($name) {
return \App\Tag::where('name', $name)->firstOrFail();
});
$router->bind('users', function ($id) {
return \App\User::where('id', $id)->firstOrFail();
});
$router->bind('messages', function ($id) {
return \App\Message::where('id', $id)->firstOrFail();
});
$router->bind('registrants', function ($id) {
return \App\Registrant::where('id', $id)->firstOrFail();
});
$router->model('image', Image::class);
}