A
A
Anton Shelestov2015-06-17 12:56:17
Laravel
Anton Shelestov, 2015-06-17 12:56:17

How to change error message in Laravel?

Hello.
Error logs contain messages like:

[2015-06-17 12:43:32] local.ERROR: exception 'Symfony\Component\Debug\Exception\FatalErrorException' with message 'Class 'App\Http\Middleware\TokenMismatchException' not found' in ..................................../public_html/app/Http/Middleware/VerifyCsrfToken.php:29

As I understand it, these are errors about the fact that the lifetime of the session token has expired and such an error occurs during some action.
In the config, the display of errors is turned on, it turns out that everyone who has this happens sees such an error.
Is it possible to make the user instead of the error shown by laravel show a message like "Session expired due to long inactivity" or something like that.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
D', 2015-06-17
@Denormalization

So why include DEBUG on the market ?
In .env write DEBUG=false .
You can also write your own processing logic in the render method in app/Exceptions/Handler.php

A
Anton Shelestov, 2015-06-17
@ShelestovAnt

<?php namespace App\Http\Middleware;

use Closure;
use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as BaseVerifier;

class VerifyCsrfToken extends BaseVerifier {

  /**
   * Handle an incoming request.
   *
   * @param  \Illuminate\Http\Request  $request
   * @param  \Closure  $next
   * @return mixed
   */
    protected $except_urls = [
        'tarif',
    ];
  public function handle($request, Closure $next)
  {
    //return parent::handle($request, $next);
    
        $regex = '#' . implode('|', $this->except_urls) . '#';

        if ($this->isReading($request) || $this->tokensMatch($request) || preg_match($regex, $request->path()))
        {
            return $this->addCookieToResponse($request, $next($request));
        }

        throw new TokenMismatchException;
  }

}

Here is the contents of the file,

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question