dtbsezxw28056 2017-09-27 15:27
浏览 86
已采纳

Laravel - 致命错误:未捕获错误:未找到类'Auth'

I got this Error Message:

Fatal error: Uncaught Error: Class 'Auth' not found in F:\projects\websites\main_website\app\Exceptions\Handler.php:65 Stack trace: #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} thrown in F:\projects\websites\main_website\app\Exceptions\Handler.php on line 65

Code its happening on:

$errorLog->error_happened_to = (Auth::check() ? Auth::user()->username : 'Guest');

Whole class:

<?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);
    }
}
  • 写回答

3条回答 默认 最新

  • dongxibeng5324 2017-09-27 15:35
    关注

    As I said in my earlier comment, use the full namespace in your use statement.

    Replace your use Auth; with this.

    use Illuminate\Support\Facades\Auth;

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度