本文整理汇总了PHP中app\Page::findBySlugOrFail方法的典型用法代码示例。如果您正苦于以下问题:PHP Page::findBySlugOrFail方法的具体用法?PHP Page::findBySlugOrFail怎么用?PHP Page::findBySlugOrFail使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\Page
的用法示例。
在下文中一共展示了Page::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: destroy
/**
* Remove the specified resource from storage.
* @param string $slug
* @return Response
*/
public function destroy($slug)
{
// Delete
$page = Page::findBySlugOrFail($slug, false);
$status = $page->delete();
// Flash message
if ($status) {
Flash::success('Page Deleted', "The page '" . $page->title . "' was successfully deleted.");
} else {
Flash::error('Error', "Something went wrong while trying to delete the page '" . $page->title . "'.");
}
// Redirect
return redirect(route('page.index'));
}