Advertisement
321zeno

Laravel show 404 in a layout view

May 24th, 2015
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.86 KB | None | 0 0
  1. //original source unknown
  2. <?php
  3.  
  4. App::error(function(Exception $exception, $code) {
  5.  
  6.     if ($exception instanceof \Symfony\Component\HttpKernel\Exception\NotFoundHttpException) {
  7.       Log::error('NotFoundHttpException Route: ' . Request::url() );
  8.     }
  9.  
  10.     Log::error($exception);
  11.  
  12.     // HTML output on staging and production only
  13.     if (!Config::get('app.debug'))
  14.         return App::make("ErrorsController")->callAction("error", ['code'=>$code]);
  15. });
  16.  
  17. //errors controller
  18.  
  19. <?php
  20.  
  21. class ErrorsController extends BaseController {
  22.  
  23.     protected $layout = "layouts.frontend";
  24.  
  25.     public function error($code) {
  26.         switch ($code) {
  27.             case 404:
  28.                 $this->layout->content = View::make('errors.404');
  29.             break;
  30.  
  31.             default:
  32.                 $this->layout->content = View::make('errors.500');
  33.             break;
  34.         }
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement