如何将 App\Exceptions 从 laravel 7 升级到 laravel 8

Posted

技术标签:

【中文标题】如何将 App\\Exceptions 从 laravel 7 升级到 laravel 8【英文标题】:How to upgrade App\Exceptions from laravel 7 to laravel 8如何将 App\Exceptions 从 laravel 7 升级到 laravel 8 【发布时间】:2021-10-09 20:24:08 【问题描述】:

如何升级 App\Exceptions;从 laravel 7 到 laravel 8

public function render($request, Throwable $exception)
    
        if ($exception instanceof UnauthorizedException) 
            if (Auth::user() instanceof Admin) 
                return redirect()->route('dashboard');
            
            return redirect()->route('home');
        
        return parent::render($request, $exception);
    

【问题讨论】:

来自文档laravel.com/docs/8.x/errors#rendering-exceptions 【参考方案1】:

请更改您的app/Exceptions/Handler.php,如下所示

<?php

namespace App\Exceptions;

use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Throwable;

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 = [
        'current_password',
        'password',
        'password_confirmation',
    ];

    /**
     * Register the exception handling callbacks for the application.
     *
     * @return void
     */
    public function register()
    
        $this->reportable(function (Throwable $e) 
            //
        );
    

【讨论】:

以上是关于如何将 App\Exceptions 从 laravel 7 升级到 laravel 8的主要内容,如果未能解决你的问题,请参考以下文章

Laravel 错误声明 App\Exceptions\Handler::report(Throwable $exception) [关闭]

如何从 Windows 命令提示符在 Laravel 中运行 PHPUnit

Laravel 5.8 到 6.x 升级错误 - App\Exceptions\Handler::renderHttpException 声明

在 App\Exceptions\Handler.php 的 render() 方法中使用 $exception 变量时出现致命错误

谁有看过Lara in trouble

976 B. Lara Croft and the New Game