本文整理汇总了PHP中app\Category::findBySlugOrFail方法的典型用法代码示例。如果您正苦于以下问题:PHP Category::findBySlugOrFail方法的具体用法?PHP Category::findBySlugOrFail怎么用?PHP Category::findBySlugOrFail使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\Category
的用法示例。
在下文中一共展示了Category::findBySlugOrFail方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: boot
/**
* Define your route model bindings, pattern filters, etc.
*
* @return void
*/
public function boot()
{
parent::boot();
Route::model('article', Article::class);
Route::bind('article_slug', function ($slug) {
return Article::findBySlugOrFail($slug);
});
Route::model('category', Category::class);
Route::bind('category_slug', function ($slug) {
return Category::findBySlugOrFail($slug);
});
Route::model('language', Language::class);
Route::model('page', Page::class);
Route::bind('page_slug', function ($slug) {
return Page::findBySlugOrFail($slug);
});
Route::model('setting', Setting::class);
Route::model('user', User::class);
}
示例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->model('article', 'App\\Article');
$router->bind('article_slug', function ($slug) {
return Article::findBySlugOrFail($slug);
});
$router->model('category', 'App\\Category');
$router->bind('category_slug', function ($slug) {
return Category::findBySlugOrFail($slug);
});
$router->model('language', 'App\\Language');
$router->model('page', 'App\\Page');
$router->bind('page_slug', function ($slug) {
return Page::findBySlugOrFail($slug);
});
$router->model('setting', 'App\\Setting');
$router->model('user', 'App\\User');
}
示例3: index
/**
* Show the category articles
*
* @param String $slug
* @return Response
*/
public function index(string $slug)
{
$category = Category::findBySlugOrFail($slug);
$articles = $category->articles()->published()->orderBy('published_at', 'desc')->paginate(5);
return view('application.category.index', compact('articles', 'category'));
}