Search
 
SCRIPT & CODE EXAMPLE
 

PHP

Laravel catch TokenMismatchException

<?php namespace AppExceptions;
use Exception;
use IlluminateFoundationExceptionsHandler as ExceptionHandler;
use IlluminateSessionTokenMismatchException;


class Handler extends ExceptionHandler {


    /**
     * A list of the exception types that should not be reported.
     *
     * @var array
     */
    protected $dontReport = [
        'SymfonyComponentHttpKernelExceptionHttpException'
    ];
    /**
     * 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  IlluminateHttpRequest  $request
     * @param  Exception  $e
     * @return IlluminateHttpResponse
     */
    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);
    }
}
Comment

PREVIOUS NEXT
Code Example
Php :: php barcode generator 
Php :: what are the different types of PHP variables? 
Php :: php if isset 
Php :: Logging a Massage php 
Php :: Merge Two Collection 
Php :: laravel mass update relationship 
Php :: auth user with relation laravel 
Php :: check dir php 
Php :: php is closure 
Php :: laravel env use other env variables 
Php :: laravel create get id 
Php :: what is Trustproxies handle in laravel 
Php :: laravel echo 
Php :: mail function php not working 
Php :: woocommerce_product_query 
Php :: php delete file 
Php :: cakephp 
Php :: how to make a variable in php 
Php :: mailjet 
Php :: define multiple variables in one line php 
Php :: how to add drop a table in phpmyadmin 
Php :: merge strings in php 
Php :: iterator 
Php :: auto logout when session expires laravel 
Php :: php save array to files a 
Php :: magento 2 add cc transportbuilder 
Php :: storefront product search 
Php :: wordpress page template comment 
Php :: Protect Your Site from Malicious Requests 
Php :: Check box group submit (php) 
ADD CONTENT
Topic
Content
Source link
Name
9+4 =