Better solution, use this instead.
You'll have to implement a custom middleware which you can create with the artisan command:
php artisan make:middleware EnsureEmailIsVerified
EnsureEmailIsVerified.php
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Support\Facades\Redirect;
use Illuminate\Contracts\Auth\MustVerifyEmail;
class EnsureEmailIsVerified
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
if (! $request->user() ||
($request->user() instanceof MustVerifyEmail &&
! $request->user()->hasVerifiedEmail())) {
return $request->expectsJson()
? abort(403, 'YOUR CUSTOM ERROR HERE')
: Redirect::route('verification.notice');
}
return $next($request);
}
}
You will have to map the verified key in your kernel file to the new middleware.
app\Http\Kernel.php (down at the bottom):
/**
* The application's route middleware.
*
* These middleware may be assigned to groups or used individually.
*
* @var array
*/
protected $routeMiddleware = [
'auth' => \App\Http\Middleware\Authenticate::class,
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class,
'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class,
'can' => \Illuminate\Auth\Middleware\Authorize::class,
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
'signed' => \Illuminate\Routing\Middleware\ValidateSignature::class,
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
'verified' => \App\Http\Middleware\EnsureEmailIsVerified::class, // the changed line
];
Original answer
I used Notepad++'s find in file function and scanned all the files in my Laravel project for: "Your email is not verified"
It came up with one match in:
\vendor\laravel\framework\src\Illuminate\Auth\Middleware\EnsureEmailIsVerified.php
Which is this file:
<?php
namespace Illuminate\Auth\Middleware;
use Closure;
use Illuminate\Support\Facades\Redirect;
use Illuminate\Contracts\Auth\MustVerifyEmail;
class EnsureEmailIsVerified
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return \Illuminate\Http\Response|\Illuminate\Http\RedirectResponse
*/
public function handle($request, Closure $next)
{
if (! $request->user() ||
($request->user() instanceof MustVerifyEmail &&
! $request->user()->hasVerifiedEmail())) {
return $request->expectsJson()
? abort(403, 'Your email address is not verified.')
: Redirect::route('verification.notice');
}
return $next($request);
}
}
I'm guessing that if you change this line: ? abort(403, 'Your email address is not verified.')
To whatever you want the error to be, for example: ? abort(403, 'Please, verify your email.')
That it will display that. (Please confirm this if you try it).
There's one minor issue with this solution. Since your .gitignore file tells git to ignore the vendor folder, it won't be pushed to an external repo when pushing.
You will need to change the .gitignore file.
Laravel updates will also revert this change, so you will have to rewrite it, there's a better solution at the top of this answer now.