Skip to content

Commit d7e5cfb

Browse files
committed
修改5.3自动生成的权限不带admin.的问题
1 parent b91bdf7 commit d7e5cfb

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

app/Http/Middleware/AuthenticateAdmin.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
namespace App\Http\Middleware;
44

55
use Closure;
6-
use Route,URL,Auth;
6+
use Route, URL, Auth;
77

88
class AuthenticateAdmin
99
{
1010

1111
protected $except = [
12-
'admin/index'
12+
'admin/index',
1313
];
1414

1515
/**
@@ -20,17 +20,18 @@ class AuthenticateAdmin
2020
*/
2121
public function handle($request, Closure $next)
2222
{
23-
if(Auth::guard('admin')->user()->id === 1){
23+
if (Auth::guard('admin')->user()->id === 1) {
2424
return $next($request);
2525
}
2626

2727
$previousUrl = URL::previous();
28-
if(!\Gate::check(Route::currentRouteName())) {
29-
if($request->ajax() && ($request->getMethod() != 'GET')) {
28+
$routeName = starts_with(Route::currentRouteName(), 'admin.') ? Route::currentRouteName() : 'admin.' . Route::currentRouteName();
29+
if (!\Gate::check($routeName)) {
30+
if ($request->ajax() && ($request->getMethod() != 'GET')) {
3031
return response()->json([
3132
'status' => -1,
32-
'code' => 403,
33-
'msg' => '您没有权限执行此操作'
33+
'code' => 403,
34+
'msg' => '您没有权限执行此操作',
3435
]);
3536
} else {
3637
return response()->view('admin.errors.403', compact('previousUrl'));

0 commit comments

Comments
 (0)