我正在构建Laravel 5.4应用程序,并如下设置了我的 routes \ web.php :
<?php
Route::get('/', 'PublicController@home')->name('home');
Route::get('/about', 'PublicController@about')->name('about');
Route::get('/contact', 'PublicController@contact')->name('contact');
Route::post('/contact', 'PublicController@sendMessage')->name('contact.send');
Route::prefix('admin')->group(function () {
Auth::routes();
Route::middleware(['auth'])->group(function () {
Route::get('/', 'DashboardController@index')->name('dashboard');
Route::get('user', 'UserController@index')->name('user.profile');
Route::post('user/update', 'UserController@update')->name('user.update');
});
});
要删除其他跟踪并跟踪修改后的 App \ Exceptions \ Handler; 类,如下所示:
<?php
namespace App\Exceptions;
use Exception;
use Illuminate\Auth\AuthenticationException;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
class Handler extends ExceptionHandler
{
protected $dontReport = [
\Illuminate\Auth\AuthenticationException::class,
\Illuminate\Auth\Access\AuthorizationException::class,
\Symfony\Component\HttpKernel\Exception\HttpException::class,
\Illuminate\Database\Eloquent\ModelNotFoundException::class,
\Illuminate\Session\TokenMismatchException::class,
\Illuminate\Validation\ValidationException::class,
];
public function report(Exception $e)
{
if (!config('app.debug')) {
\Log::error('['.$e->getCode().'] "'.$e->getMessage().'" on line '.$e->getTrace()[0]['line'].' of file '.$e->getTrace()[0]['file']);
} else {
parent::report($e);
}
}
public function render($request, Exception $exception)
{
return parent::render($request, $exception);
}
protected function unauthenticated($request, AuthenticationException $exception)
{
if ($request->expectsJson()) {
return response()->json(['error' => 'Unauthenticated.'], 401);
}
return redirect()->guest(route('login'));
}
}
在我的 config \ app.php 文件中,我更改了日志级别,如下所示:
'log_level' => env('APP_LOG_LEVEL', 'error'),
现在,无论何时,我都会访问任何公共路线,例如mydomain.com/或mydomain.com/about,重定向工作正常,没有任何前端错误,但是Laravel将以下错误记录到日志文件中:
[2019-05-21 05:12:32] production.ERROR: [0] "" on line 546 of file
D:\laragon\www\myproject\vendor\laravel\framework\src\Illuminate\Routing\Router.php
如果我访问任何管理员(受保护的)路由,例如mydomain.com/admin或mydomain.com/admin/user,同样在前端也没有错误,但获取的日志条目如下:
[2019-05-21 05:12:47] production.ERROR: [0] "Unauthenticated." on line 294 of file
D:\laragon\www\myproject\vendor\laravel\framework\src\Illuminate\Auth\AuthManager.php
[2019-05-21 05:12:47] production.ERROR: [0] "" on line 546 of file
D:\laragon\www\myproject\vendor\laravel\framework\src\Illuminate\Routing\Router.php
现在我的问题是:
PS 。我正在使用PHP版本7.2.11