In my my laravel 5.7.3 application I use https://github.com/jrean/laravel-user-verification extention and with use of middleware I generate UserNotVerifiedException error when logged is not verified But with excception I want to make logout and redirect to /login page and reading https://laravel.com/docs/master/errors#the-exception-handler doc in file app/Exceptions/Handler.php I do :
<?php
namespace App\Exceptions;
use Exception;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Auth;
use App\Exceptions\UserNotVerifiedException;
use Illuminate\Support\Facades\Redirect;
use Illuminate\Foundation\Auth\RegistersUsers;
use Jrean\UserVerification\Traits\VerifiesUsers; // Do I need to add these declarations here ?
use Jrean\UserVerification\Facades\UserVerification;
class Handler extends ExceptionHandler
{
use RegistersUsers;
use VerifiesUsers;
protected $dontReport = [
//
];
protected $dontFlash = [
'password',
'password_confirmation',
];
public function report(Exception $exception)
{
parent::report($exception);
}
public function render($request, Exception $exception)
{
dump($exception);
if ($exception instanceof UserNotVerifiedException) {
dump("Make Logout");
Auth::logout();
return redirect('/admin/dashboard/index');
}
return parent::render($request, $exception);
}
}
In dump file I see first message, but not second(and why there is no redirection):
UserNotVerifiedException {#509 ▼
#message: "This user is not verified."
#code: 0
#file: "/mnt/_work_sdb8/wwwroot/lar/Votes/vendor/jrean/laravel-user-verification/src/Middleware/IsVerified.php"
#line: 26
trace: {▶}
}
Which is valid way ?
Thanks!
You can try to put the original namespace like:
if ($exception instanceof \Jrean\UserVerification\Exceptions\UserNotVerifiedException) {
dump("Make Logout");
Auth::logout();
return redirect('/admin/dashboard/index');
}