Create a middleware
and set up your project on the administration routes to be checked whether or not you can, follow the step by step:
At the console type:
php artisan make:middleware CheckStatus
a app/Http/Middleware
file will be created in the CheckStatus.php
folder 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
created CheckStatus
between app/Http/Kernel.php
in $routeMiddleware
add a key (< strong> 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 in your route (s) ( Route
):
On a route:
Route::get('admin/', function ()
{
})->middleware('auth.status');
In a route group:
Route::group(['middleware' => 'auth.status'], function () {
Route::get('/admin/change', function ()
{
});
Route::get('admin/profile', function ()
{
});
});
It can also be added directly in Controller
:
class AdminController extends Controller
{
public function __construct()
{
$this->middleware('auth.status');
}
}
In this link has the translation made by Artisans group laravel
References: