Laravel - 致命错误:未捕获的错误:找不到类'Auth'
Posted
技术标签:
【中文标题】Laravel - 致命错误:未捕获的错误:找不到类\'Auth\'【英文标题】:Laravel - Fatal error: Uncaught Error: Class 'Auth' not foundLaravel - 致命错误:未捕获的错误:找不到类'Auth' 【发布时间】:2018-03-09 04:06:34 【问题描述】:我收到此错误消息:
致命错误:未捕获的错误:在 F:\projects\websites\main_website\app\Exceptions\Handler.php:65 中找不到类 'Auth' 堆栈跟踪:#0 F:\projects\websites\main_website\vendor\ laravel\framework\src\Illuminate\Foundation\Http\Kernel.php(326): App\Exceptions\Handler->render(Object(Illuminate\Http\Request), Object(Symfony\Component\Debug\Exception\FatalThrowableError)) #1 F:\projects\websites\main_website\vendor\laravel\framework\src\Illuminate\Foundation\Http\Kernel.php(124): Illuminate\Foundation\Http\Kernel->renderException(Object(Illuminate\Http\Request ), Object(Symfony\Component\Debug\Exception\FatalThrowableError)) #2 F:\projects\websites\main_website\public\index.php(56): Illuminate\Foundation\Http\Kernel->handle(Object(Illuminate\ Http\Request)) #3 main 在第 65 行的 F:\projects\websites\main_website\app\Exceptions\Handler.php 中抛出
代码发生在:
$errorLog->error_happened_to = (Auth::check() ? Auth::user()->username : 'Guest');
全班:
<?php
namespace App\Exceptions;
use Exception;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use App\Database\Ec9\Website\ErrorLog;
use Jenssegers\Agent\Agent;
use Auth;
class Handler extends ExceptionHandler
/**
* A list of the exception types that are not reported.
*
* @var array
*/
protected $dontReport = [
//
];
/**
* A list of the inputs that are never flashed for validation exceptions.
*
* @var array
*/
protected $dontFlash = [
'password',
'password_confirmation',
];
/**
* Report or log an exception.
*
* This is a great spot to send exceptions to Sentry, Bugsnag, etc.
*
* @param \Exception $exception
* @return void
*/
public function report(Exception $exception)
parent::report($exception);
/**
* Render an exception into an HTTP response.
*
* @param \Illuminate\Http\Request $request
* @param \Exception $exception
* @return \Illuminate\Http\Response
*/
public function render($request, Exception $exception)
if (strlen($exception->getMessage()) > 0)
$agent = new Agent();
$errorLog = new ErrorLog;
$errorLog->error_message = $exception->getMessage();
$errorLog->error_file = $exception->getFile();
$errorLog->error_line = $exception->getLine();
$errorLog->request_ip = $request->ip();
$errorLog->request_url = $request->root();
$errorLog->request_device = $agent->isDesktop() ? 'Desktop' : ($agent->isMobile() ? 'Mobile' : 'Tablet');
$errorLog->request_system = $agent->platform() . ' ' . $agent->version($agent->platform());
$errorLog->request_browser = $agent->browser();
$errorLog->error_happened_to = (Auth::check() ? Auth::user()->username : 'Guest');
$errorLog->save();
return parent::render($request, $exception);
【问题讨论】:
您是否修改过任何核心文件?我建议尝试使用类的完整命名空间,而不仅仅是 auth。 【参考方案1】:将use Auth;
替换为use Illuminate\Support\Facades\Auth;
【讨论】:
【参考方案2】:正如我在之前的评论中所说,在 use
语句中使用完整的命名空间。
用这个替换你的use Auth;
。
use Illuminate\Support\Facades\Auth;
【讨论】:
好奇,这两者有什么区别?【参考方案3】:对于想要解决此问题的人,我通过将 use Auth;
替换为 use Illuminate\Support\Facades\Auth;
来修复它
【讨论】:
【参考方案4】:对于遇到相同错误消息的人。
此问题可能与缺少以下目录之一有关:
storage/framework/cache
storage/framework/sessions
storage/framework/views
bootstrap/cache
它们都必须是可写的。
【讨论】:
以上是关于Laravel - 致命错误:未捕获的错误:找不到类'Auth'的主要内容,如果未能解决你的问题,请参考以下文章
为啥致命错误:未捕获的错误:找不到类“Illuminate\Foundation\Application”
为啥我收到 PHP 致命错误:未捕获的错误:找不到类“MyClass”? [复制]
我有这样的问题期待帮助致命错误:未捕获的错误:找不到类'Illuminate\Foundation\Application'[重复]