Kernel.php ;
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,
'Admin' => \App\Http\Middleware\Admin::class,
];
web.php ;
Route::group(['middleware' => ['Admin']], function () {
...
... Rotalarınız gelecek ,bu kısıma sadece admin yetkisi olanlar giriş yapabilir .
...
}
Middleware/Admin.php
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Contracts\Auth\Guard;
class Admin
{
/**
* The Guard implementation.
*
* @var Guard
*/
protected $auth;
/**
* Create a new filter instance.
*
* @param Guard $auth
* @return void
*/
public function __construct(Guard $auth)
{
$this->auth = $auth;
}
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
if (!$this->auth->check() or $this->auth->user()->usertype !== 'Admin') {
if ($request->ajax()) {
return array('errors', 'You are not an Admin..');
} else {
\Session::flash('error.message', 'You have no permission for this!');
return redirect('/');
}
}
return $next($request);
}
}
Benim user tablomda usertype diye bir alanım var ve default olarak User ayarlı , admin panelimden Admin olarak değiştirdigimde Şartlarımı saglamıs oluyor ve admin panelime giriş yapabiliyor.