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

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

如何在 laravel 中翻譯油門?

如何在 laravel 中翻譯油門?

PHP
不負(fù)相思意 2022-01-24 09:13:48
我正在使用 Laravel 5.7 版本。我正在使用throttleinKernel.php來(lái)避免用戶發(fā)送超過(guò) 60 個(gè)查詢。我想翻譯它的消息“Too Many Attempts”。并使用自己的消息。我怎樣才能在laravel中做到這一點(diǎn)?我在哪里可以找到那個(gè)?
查看完整描述

4 回答

?
叮當(dāng)貓咪

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

use Symfony\Component\HttpKernel\Exception\HttpException;


if($exception instanceof HttpException && $exception->getStatusCode() == 429) {

return response()->json([

'message' => 'Too Many Attempts',

'code' => 429

], 429)->withHeaders($exception->getHeaders());

}


查看完整回答
反對(duì) 回復(fù) 2022-01-24
?
GCT1015

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

在您的 Laravel 異常處理程序中,您可以在渲染之前處理該異常并將該異常替換為您的自定義異常。


在app/Exceptions/Handler.php


/**

 * Render an exception into an HTTP response.

 *

 * @param  \Illuminate\Http\Request  $request

 * @param  \Exception  $exception

 * @return \Illuminate\Http\Response|\Illuminate\Http\JsonResponse

 */

public function render($request, Exception $exception)

{

    if($exception instanceof ThrottleRequestsException) {

        return parent::render(

            $request, new ThrottleRequestsException(

                'Your message',

                $exception->getPrevious(),

                $exception->getHeaders(),

                $exception->getCode()

            )

        );

    }


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

}


查看完整回答
反對(duì) 回復(fù) 2022-01-24
?
阿波羅的戰(zhàn)車

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

您可以在app/Http/Middlewares文件夾中創(chuàng)建自定義中間件,擴(kuò)展基\Illuminate\Routing\Middleware\ThrottleRequests類并覆蓋buildException方法(此處為原始實(shí)現(xiàn))。

然后將throttle中間件分配給您的自定義中間件類Kernel.php


查看完整回答
反對(duì) 回復(fù) 2022-01-24
?
精慕HU

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

我在 Laravel 的這個(gè)地址找到了它的文件: vendor\laravel\framework\src\llluminate\Routing\Middleware\ThrottleRequests.php


protected function buildException($key, $maxAttempts)

    {

        $retryAfter = $this->getTimeUntilNextRetry($key);


        $headers = $this->getHeaders(

            $maxAttempts,

            $this->calculateRemainingAttempts($key, $maxAttempts, $retryAfter),

            $retryAfter

        );


        return new ThrottleRequestsException(

            'You can change message here and put your message!', null, $headers

        );

    }


查看完整回答
反對(duì) 回復(fù) 2022-01-24
  • 4 回答
  • 0 關(guān)注
  • 189 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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