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);
}
...
}