Create a middleware
and configure your project on the administration routes whether you can or not, follow the step by step:
On the console type:
php artisan make:middleware CheckStatus
will be created in the folder app/Http/Middleware
an archive CheckStatus.php
edit as follows:
<?php
namespace App\Http\Middleware;
use Closure;
class CheckStatus
{
public function handle($request, Closure $next)
{
if (\Auth::user()->status == 1)
{
return redirect('home');
}
return $next($request);
}
}
to register this middleware
servant CheckStatus
amid app/Http/Kernel.php
in $routeMiddleware
add a key (auth status.) as follows:
protected $routeMiddleware = [
'auth' => \Illuminate\Auth\Middleware\Authenticate::class,
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class,
'can' => \Illuminate\Auth\Middleware\Authorize::class,
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
'auth.status' => \App\Http\Middleware\CheckStatus::class,
];
then add on your route(s) (Route
):
On a route:
Route::get('admin/', function ()
{
})->middleware('auth.status');
In a group of routes:
Route::group(['middleware' => 'auth.status'], function () {
Route::get('/admin/change', function ()
{
});
Route::get('admin/profile', function ()
{
});
});
Can also be added direct on Controller
:
class AdminController extends Controller
{
public function __construct()
{
$this->middleware('auth.status');
}
}
In that link has the translation made by Craftsmen group Larable.
References:
That field
status
will be changed at your discretion, right? It’s just one more step of verification until the login is successful?– juniorgarcia