Last active
February 22, 2016 16:23
-
-
Save kneipp/9b77c84c52ddac489464 to your computer and use it in GitHub Desktop.
5.2
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; | |
use Illuminate\Foundation\Http\Kernel as HttpKernel; | |
class Kernel extends HttpKernel | |
{ | |
/** | |
* The application's global HTTP middleware stack. | |
* | |
* These middleware are run during every request to your application. | |
* | |
* @var array | |
*/ | |
protected $middleware = [ | |
\Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class, | |
]; | |
/** | |
* The application's route middleware groups. | |
* | |
* @var array | |
*/ | |
protected $middlewareGroups = [ | |
'web' => [ | |
\App\Http\Middleware\EncryptCookies::class, | |
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class, | |
\Illuminate\Session\Middleware\StartSession::class, | |
\Illuminate\View\Middleware\ShareErrorsFromSession::class, | |
\App\Http\Middleware\VerifyCsrfToken::class, | |
], | |
'api' => [ | |
'throttle:60,1', | |
], | |
// | |
// 'admin' => [ | |
// 'web', | |
// 'auth' | |
// ] | |
]; | |
/** | |
* The application's route middleware. | |
* | |
* These middleware may be assigned to groups or used individually. | |
* | |
* @var array | |
*/ | |
protected $routeMiddleware = [ | |
'auth' => \App\Http\Middleware\Authenticate::class, | |
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class, | |
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class, | |
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class, | |
'admin' => \App\Http\Middleware\AdminAuthentication::class, | |
]; | |
} | |
<?php | |
namespace App\Http\Middleware; | |
use Closure; | |
use Illuminate\Contracts\Auth\Guard; | |
use Illuminate\Http\RedirectResponse; | |
use Illuminate\Support\Facades\Auth; | |
use Illuminate\Support\Facades\Redirect; | |
class AdminAuthentication | |
{ | |
public function __construct(Guard $auth) | |
{ | |
$this->auth = $auth; | |
//dd($this->auth->user()); | |
} | |
/** | |
* Handle an incoming request. | |
* | |
* @param \Illuminate\Http\Request $request | |
* @param \Closure $next | |
* @return mixed | |
*/ | |
public function handle($request, Closure $next, $guard = null) | |
{ | |
//dd(Auth::user()); | |
//dd($request->user()); | |
if ($request->user()->is_admin == true) { | |
return $next($request); | |
} | |
return new RedirectResponse(url('/')); | |
} | |
} | |
<?php | |
Route::get('/', function () { | |
return view('welcome'); | |
}); | |
Route::group(['middleware' => ['web']], function () { | |
Route::auth(); | |
Route::get('/home', 'HomeController@index'); | |
}); | |
Route::group(['middleware' => ['admin', 'web']], function () { | |
Route::resource('user', 'UserController', ['except' => ['show']]); | |
Route::get('user/{id}/delete', ['as' => 'user.destroy', 'uses' => 'UserController@destroy']); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment