BookStack/app/Http/Middleware/PermissionMiddleware.php

29 lines
653 B
PHP
Raw Normal View History

2015-08-29 22:03:42 +08:00
<?php
namespace BookStack\Http\Middleware;
2015-08-29 22:03:42 +08:00
use Closure;
use Illuminate\Support\Facades\Session;
class PermissionMiddleware
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @param $permission
* @return mixed
*/
public function handle($request, Closure $next, $permission)
{
if (!$request->user() || !$request->user()->can($permission)) {
Session::flash('error', trans('errors.permission'));
return redirect()->back();
}
return $next($request);
}
}