samedi 3 octobre 2015

App::abort(404) equivalent for Laravel 5?

In Laravel 4 i used to be able to simply call

App::abort(404)

Is there an equivalent in Laravel 5?

There seems to be surprisingly limited information out there about this at the time of writing. I've found discussions on how to catch NotFoundHttpExceptions but that isn't what I want, as the url structure is already processed by my routes.php file. To give some more background, here's a simplified version of what I am trying to do:

Routes.php:

Route::get('/info/{page}', array('as' => 'info', 'uses' => 'Primary@infoPage'));

Primary.php (controller)

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?
    }
}



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire