mardi 6 février 2018

Custom error pages for different view groups

My application has a landing page and an admin panel. So, I want to create different 404 pages for those views. My views folder has 2 folders: admin and site and in them I have errors folder with created 404.blade.php files. In order to achieve my aim I've overrided a method called renderHttpException(HttpException $e) in app/Exceptions/Handler.php but unfortunately it doesn't work. What is the workaround?

Here's the renderHttpException(HttpException $e) method:

protected function renderHttpException(HttpException $e) 
{
    $status = $e->getStatusCode();

    if(Request::is('/admin/*')) { 
        return response()->view("admin/errors.{$status}", ['exception' => $e], $status, $e->getHeaders());
    }else {
        return response()->view("site/errors.{$status}", ['exception' => $e], $status, $e->getHeaders());
    }    
}

And also routes:

/* Site routes */
Route::get('/', 'HomeController@index')->name('home');
Route::get('/menu', 'MenuController@index')->name('menu');

/* Admin panel routes */
Route::prefix('/admin')->namespace('Admin')->group(function () {
    Route::get('/', 'HomeController@index')->name('admin-dashboard');
    Route::get('/login', 'HomeController@showLoginForm')->name('admin-login');
    Route::get('/menu', 'MenuController@index')->name('admin-menu');
});



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire