Laravel catch TokenMismatchException
<?php namespace App\Exceptions;
use Exception;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Illuminate\Session\TokenMismatchException;
class Handler extends ExceptionHandler {
/**
* A list of the exception types that should not be reported.
*
* @var array
*/
protected $dontReport = [
'Symfony\Component\HttpKernel\Exception\HttpException'
];
/**
* Report or log an exception.
*
* This is a great spot to send exceptions to Sentry, Bugsnag, etc.
*
* @param \Exception $e
* @return void
*/
public function report(Exception $e)
{
return parent::report($e);
}
/**
* Render an exception into an HTTP response.
*
* @param \Illuminate\Http\Request $request
* @param \Exception $e
* @return \Illuminate\Http\Response
*/
public function render($request, Exception $e)
{
if ($e instanceof TokenMismatchException){
// Redirect to a form. Here is an example of how I handle mine
return redirect($request->fullUrl())->with('csrf_error',"Oops! Seems you couldn't submit form for a long time. Please try again.");
}
return parent::render($request, $e);
}
}
Also in PHP:
- array push foreach php
- date now php
- clear cache route laravel
- find string in word php
- Fatal error: Allowed memory size of 2147483648 bytes exhausted (tried to allocate 18874368 bytes) in phar:///opt/cpanel/composer/bin/composer/src/Composer/Repository/ComposerRepository.php on line 588
- debugger for php
- Jul 29th, 2020 php format
- Composer detected issues in your platform
- check key exist in array php
- convert object to array php
- command to create new laravel project
- current date into time
- check if an array index exists php
- check value of a key array php
- check for a key in array + php
- composer laravel install
- $data length in php
- bulk seed in laravel with update or create
- creating a folder from php and make it writeable for all
- fetch visitor ip address php
- carbon add minutes
- composer check php version
- Adding or Subtracting Time
- Fatal error: Allowed memory size of 1073741824 bytes exhausted (tried to allocate 20480 bytes) in /app/docroot/core/lib/Drupal/Core/Cache/DatabaseBackend.php on line 167