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');
});
It throws an error as a result:
Declaration of App\Exceptions\Handler::renderHttpException(App\Exceptions\HttpException $e) should be compatible with Illuminate\Foundation\Exceptions\Handler::renderHttpException(Symfony\Component\HttpKernel\Exception\HttpException $e)