1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- <?php
- namespace App\Http\Middleware;
- use App\Servers\MenuServer;
- use App\Servers\PermissionServer;
- use Closure;
- class PermissionMiddleware
- {
- /**
- * Handle an incoming request.
- *
- * @param \Illuminate\Http\Request $request
- * @param \Closure $next
- * @return mixed
- */
- public function handle($request, Closure $next)
- {
- $user = app('auth')->user();
- $clientRoute = request()->route()->getName();
- if (!empty($user)) MenuServer::creatServer()->sendMenu($user->{'roles_id'});
- if (in_array($clientRoute, ['login','logout', 'admin.index.ajax', 'admin.not.permission', 'admin.index', 'admin.ajaxIndex', 'admin.switch', 'admin.u_sort'])) {
- return $next($request);
- }
- $ret = PermissionServer::verifyPermission($user->{'roles_id'}, $clientRoute);
- if (empty($ret) && $user->{'id'} != 1) {
- $is_ajax = request()->ajax();
- if ($is_ajax) {
- return response()->json([
- 'status' => 'error',
- 'message' => '暂无权限',
- 'redirect' => '',
- 'callback' => '',
- 'data' => []
- ]);
- } else {
- // 当前会员没有权限
- return redirect()->route('admin.not.permission');
- }
- }
- return $next($request);
- }
- }
|