第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

在維護(hù)視圖頁(yè)面下顯示 Laravel 應(yīng)用程序中所有錯(cuò)誤/異常的站點(diǎn)

在維護(hù)視圖頁(yè)面下顯示 Laravel 應(yīng)用程序中所有錯(cuò)誤/異常的站點(diǎn)

PHP
慕虎7371278 2023-07-08 17:41:03
我是 Laravel 的初學(xué)者。我遇到了一個(gè) Laravel 應(yīng)用程序。因?yàn)槲倚枰幚硭蓄?lèi)型的異常/錯(cuò)誤。ViewExceptions、ErrorExceptions 等異常。我需要為所有這些系統(tǒng)異常、錯(cuò)誤以及所有數(shù)據(jù)庫(kù)或編碼異常和錯(cuò)誤顯示一個(gè)視圖頁(yè)面(正在維護(hù)的站點(diǎn))。我檢查了Laravel 錯(cuò)誤處理并在 google 上搜索了解決方案。但我搜索的越多,我對(duì)解決方案感到困惑。由于應(yīng)用程序已經(jīng)投入生產(chǎn),我無(wú)法更改每個(gè)控制器來(lái)處理異常。我猜測(cè),我只需要在 App/Exception/Handler 類(lèi)中進(jìn)行更改,但不確定它將如何工作。表單搜索我發(fā)現(xiàn)我必須像在 Handler 類(lèi)中那樣進(jìn)行更改:/**?* Render an exception into an HTTP response.?*?* @param? \Illuminate\Http\Request? $request?* @param? \Throwable? $exception?* @return \Illuminate\Http\Response?*/public function render($request, Throwable $exception){? ? if ($exception instanceof CustomException) {? ? ? ? return response()->view('errors.site_down', [], 500);? ? }? ? return parent::render($request, $exception);}上面的代碼沒(méi)有顯示是否存在 ViewException。我觀察到,在 .env APP_DEBUG 中為 true,在 config/app 中為 false。有影響嗎?如何將所有異常或錯(cuò)誤重定向到site_down頁(yè)面?還請(qǐng)指導(dǎo)我 laravel 中的異常和錯(cuò)誤處理。我越來(lái)越困惑了。提前致謝。
查看完整描述

3 回答

?
Qyouu

TA貢獻(xiàn)1786條經(jīng)驗(yàn) 獲得超11個(gè)贊

添加刀片頁(yè)面resources/views/errors/503.blade.php

您可以使用 Artisan 命令發(fā)布 Laravel 的錯(cuò)誤頁(yè)面模板vendor:publish。模板發(fā)布后,您可以根據(jù)自己的喜好對(duì)其進(jìn)行自定義:

php?artisan?vendor:publish?--tag=laravel-errors

此命令將在目錄中創(chuàng)建所有自定義錯(cuò)誤頁(yè)面resources/views/errors/。您可以根據(jù)需要進(jìn)行定制。

查看完整回答
反對(duì) 回復(fù) 2023-07-08
?
ITMISS

TA貢獻(xiàn)1871條經(jīng)驗(yàn) 獲得超8個(gè)贊

只需去掉 if 語(yǔ)句即可:


/**

 * Render an exception into an HTTP response.

 *

 * @param  \Illuminate\Http\Request  $request

 * @param  \Throwable  $exception

 * @return \Illuminate\Http\Response

 */

public function render($request, Throwable $exception)

{

    return response()->view('errors.site_down', [], 503);

}

如果您試圖聲稱(chēng)該網(wǎng)站已關(guān)閉以進(jìn)行維護(hù),您可能還需要返回 503。


在批評(píng)這種方法時(shí),我認(rèn)為聲稱(chēng)網(wǎng)站正在維護(hù)您的錯(cuò)誤對(duì)您的用戶來(lái)說(shuō)是不誠(chéng)實(shí)和透明的,從長(zhǎng)遠(yuǎn)來(lái)看這不會(huì)得到回報(bào)。


查看完整回答
反對(duì) 回復(fù) 2023-07-08
?
蠱毒傳說(shuō)

TA貢獻(xiàn)1895條經(jīng)驗(yàn) 獲得超3個(gè)贊

對(duì)于自定義異常,首先您必須創(chuàng)建一個(gè)自定義異常文件,最好在異常文件夾中App\Exceptions\CustomException.php


<?php


namespace App\Exceptions;


use Exception;


class CustomException extends Exception

{

    //

}

然后在你的異常處理程序文件中App\Exceptions\Handler.php


<?php


namespace App\Exceptions;


use Exception;

use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;

use App\Exceptions\CustomException as CustomException;

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 = [

        'password',

        'password_confirmation',

    ];


    /**

     * Report or log an exception.

     *

     * @param  \Throwable  $exception

     * @return void

     */

    public function report(Throwable $exception)

    {

        parent::report($exception);

    }


    /**

     * Render an exception into an HTTP response.

     *

     * @param  \Illuminate\Http\Request  $request

     * @param  \Throwable  $exception

     * @return \Illuminate\Http\Response

     */

    public function render($request, Throwable $exception)

    {

        // Thrown when a custom exception occurs.

        if ($exception instanceof CustomException) {

            return response()->view('error.page.path', [], 500);

        }


        // Thrown when an exception occurs.

        if ($exception instanceof Exception) {

            response()->view('errors.page.path', [], 500);

        }


        return parent::render($request, $exception);

    }

}

請(qǐng)記住use App\Exceptions\CustomException;在需要拋出自定義異常的地方自定義異常文件,如下所示:


use App\Exceptions\CustomException;


function test(){

    throw new CustomException('This is an error');

}


查看完整回答
反對(duì) 回復(fù) 2023-07-08
  • 3 回答
  • 0 關(guān)注
  • 180 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)