Custom error page for Laravel Signed Route

Published 11 July 2020 12:24 (1-minute read)

Every wanted to make a custom error page for Laravel Signed Route?

Freek van der Herten tweeted a nice & handy quick tip for informing your users about a temporary link that isn't valid or is expired.

<?php

namespace App\Exceptions;

use Illuminate\Routing\Exceptions\InvalidSignatureException;

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

class Handler extends ExceptionHandler
{
  ...

  public function render($request, Throwable $exception) {
    if ($exception instanceof InvalidSignatureException) {
        return response()->view('errors.link-expired')->setStatusCode(Response::HTTP_FORBIDDEN);
    }
  
    return parent::render($request, $exception);
  }

  ...
}

Robin Dirksen
Robin Dirksen

Follow me on Twitter, there I post web-related content, tips/tricks, and other interesting things.

On my blog, you can find articles that I've found useful or wanted to share with anyone else.

If you want to know more about this article or just want to talk to me, don't hesitate to reach out.

Legal