Created
February 10, 2025 13:51
-
-
Save jeffersongoncalves/1b7a0d18b437c3cdedd67bb10f6ed82a to your computer and use it in GitHub Desktop.
Middleware check user info completed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Http\Middleware; | |
use Closure; | |
use Illuminate\Http\Request; | |
use Symfony\Component\HttpFoundation\Response; | |
class CheckUserCompletedInfo | |
{ | |
/** | |
* Handle an incoming request. | |
* | |
* @param Closure(Request): (Response) $next | |
*/ | |
public function handle(Request $request, Closure $next): Response | |
{ | |
if (auth()->user()->completed) { | |
return redirect()->route('dashboard'); | |
} | |
return $next($request); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Http\Middleware; | |
use Closure; | |
use Illuminate\Http\Request; | |
use Symfony\Component\HttpFoundation\Response; | |
class CheckUserCompleteInfo | |
{ | |
/** | |
* Handle an incoming request. | |
* | |
* @param Closure(Request): (Response) $next | |
*/ | |
public function handle(Request $request, Closure $next): Response | |
{ | |
if (! auth()->user()->completed) { | |
return redirect()->route('first-access'); | |
} | |
return $next($request); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
Route::middleware('auth') | |
->group(function () { | |
Route::get('/primeiro-acesso', Platform\FirstAccessController::class) | |
->middleware(CheckUserCompletedInfo::class) | |
->name('first-access') | |
->withoutScopedBindings(); | |
Route::middleware(CheckUserCompleteInfo::class) | |
->group(function () { | |
// Rotas protegidas | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment