【发布时间】:2015-12-31 13:23:39
【问题描述】:
在Laravel 4我曾经可以简单地调用
App::abort(404)
Laravel 5 中是否有等价物?
在撰写本文时,关于此的信息似乎非常有限。我找到了关于如何 catch NotFoundHttpExceptions 的讨论,但这不是我想要的,因为我的 routes.php 文件已经处理了 url 结构。为了提供更多背景知识,这是我正在尝试做的简化版本:
Routes.php:
Route::get('/info/{page}', array('as' => 'info', 'uses' => 'Primary@infoPage'));
Primary.php(控制器)
public function infoPage($page){
$pageData = DB::table('pages')->where('url_title', $page)->first();
if(!empty($pageData)){
// great, there's a corresponding row in the database for this page, go ahead and do stuff...
}else {
// This page doesn't exist, please abort with a 404 error... but how?
}
}
【问题讨论】:
标签: php laravel laravel-5 http-status-code-404