【问题标题】:How to redirect to 404 use NotFoundHttpException on Handle.php laravel 8How to redirect to 404 use NotFoundHttpException on Handle.php laravel 8
【发布时间】:2022-11-20 11:07:43
【问题描述】:

i want to redirect all 404 error to home page with handle.php , i use laravel 8 please help me.

    <?php

namespace App\Exceptions;

use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;

use Throwable;

class Handler extends ExceptionHandler
    /**
     * Register the exception handling callbacks for the application.
     *
     * @return void
     */
    public function register()
    {
        $this->renderable(function (NotFoundHttpException $e, $request) {
          
        });
    }

【问题讨论】:

    标签: php laravel laravel-8


    【解决方案1】:

    You can just return redirect back to the home page :

    $this->renderable(function(NotFoundHttpException $ex, $request) {
        return redirect('/');
    })
    

    【讨论】:

      猜你喜欢
      • 2022-12-27
      • 2020-07-21
      • 2022-12-02
      • 2022-11-20
      • 2022-12-27
      • 2022-12-01
      • 2022-12-27
      • 2016-12-02
      • 2022-12-28
      相关资源
      最近更新 更多