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