BookStack/app/Http/Middleware/PermissionMiddleware.php

29 lines
619 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;
class PermissionMiddleware
{
/**
* Handle an incoming request.
*
2021-06-26 23:23:15 +08:00
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @param $permission
*
2015-08-29 22:03:42 +08:00
* @return mixed
*/
public function handle($request, Closure $next, $permission)
{
if (!$request->user() || !$request->user()->can($permission)) {
session()->flash('error', trans('errors.permission'));
2021-06-26 23:23:15 +08:00
2015-08-29 22:03:42 +08:00
return redirect()->back();
}
return $next($request);
}
}