我对http异常有疑问。实际上,我创建的404视图不会出现。仅显示默认视图(当我在URL http://127.0.0.1:8000/fr/sdfsdf
中书写时)。
我的视图显示图像,标题和错误原因以及视图路径:resources/views/errors/404.blade.php
:
@extends('layout')
@section('title',trans('errors.404'))
@section('body')
<div class="container-fluid">
<div class="containe center_vertical_errors">
<div class="row">
<div class="col-xs-12 text-center" >
<h1 class="text-uppercase">{{trans('errors.404')}}</h1>
</div>
<div class="col-xs-12 logo-error">
<img src="{{asset('image/logo.png')}}" alt="logo" width="300" height="300" title="logo" class="img-responsive img-centre-horizontal"/>
</div>
<div class="col-xs-12 text-center reason-error" >
<p class="text-uppercase">{{trans('errors.reason404')}}</p>
</div>
</div>
</div>
</div>
@stop
Handler的代码:
...
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
class Handler extends ExceptionHandler
{
...
public function render($request, Exception $exception){
if ($this->isHttpException($exception))
{
if($exception instanceof NotFoundHttpException)
{
return response()->view('errors.404', [], 404);
}
}
return parent::render($request, $exception);
}
}
路线代码:
Route::get('/', function () {return view('home/home');})->name('home');
Route::get(trans('routes.news'),'PublicationController@index')->name('news');
Route::post(trans('routes.news'),'PublicationController@index')->name('news');
Route::get('/{slug}/{id}','PublicationController@show')->name('showNew');
Route::get(trans('routes.team'), function () {
return view('equipe/equipe');
})->name('team');
Route::get('lang/{language}', 'LanguageController@switchLang')->name('lang.switch');
Route::put(trans('routes.changeDefaul'),'UtilisateurController@changeDefaul')->name('changeDefaul');
Route::get(trans('routes.postNew'),'ActualiteController@create')->name('postNew');
Route::post(trans('routes.postNew'),'ActualiteController@store')->name('postNew');
Auth::routes();
Route::get('/Utilisateur','UtilisateurController@index')->name('user');
Route::get(trans('routes.pdf'), 'PDFController@index')->name('pdf');
Route::get(trans('routes.displayNew'),'ActualiteController@index')->name('displayNew');
Route::put(trans('routes.displayOneNew'),'ActualiteController@get')->name('displayOneNew');
Route::put('/actualite/suppressionActu','ActualiteController@delete')->name('actuSuppr');
Route::put(trans('routes.updateActuality'),'ActualiteController@publier')->name('updateActuality');
Route::post('actualite/update','ActualiteController@update')->name('updateNew');
Route::get('/admin','AdminController@index')->name('adminIndex');
Route::get('/fileManager','FileManagerController@index')->name('fileManager');
感谢大家的帮助
我做了研究以找到解决方案,但是我什么也找不到。
答案 0 :(得分:0)
实际路径必须为resources/views/errors/404.blade.php
。不知道这是否是您的错字,但您错过了views
目录。
对于默认的5.6行为,您也可以将app/Exceptions/Handler.php
内的render函数保留为:
public function render($request, Exception $exception)
{
return parent::render($request, $exception);
}