Skip to content
This repository was archived by the owner on Nov 23, 2020. It is now read-only.

Commit f05430b

Browse files
committed
ability to customize admin middleware; fixes #67
1 parent 84a4106 commit f05430b

5 files changed

Lines changed: 25 additions & 3 deletions

File tree

src/BaseServiceProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public function register()
119119

120120
public function registerAdminMiddleware(Router $router)
121121
{
122-
Route::aliasMiddleware('admin', \Backpack\Base\app\Http\Middleware\Admin::class);
122+
Route::aliasMiddleware(config('backpack.base.middleware_key'), config('backpack.base.middleware_class'));
123123
}
124124

125125
public function publishFiles()

src/app/Http/Controllers/AdminController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class AdminController extends Controller
1111
*/
1212
public function __construct()
1313
{
14-
$this->middleware('admin');
14+
$this->middleware(backpack_middleware());
1515
}
1616

1717
/**

src/app/Http/Controllers/Auth/MyAccountController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class MyAccountController extends Controller
1515

1616
public function __construct()
1717
{
18-
$this->middleware('admin');
18+
$this->middleware(backpack_middleware());
1919
}
2020

2121
/**

src/config/backpack/base.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,13 @@
8181
// Fully qualified namespace of the User model
8282
'user_model_fqn' => '\App\User',
8383

84+
// The class for the middleware that checks if the visitor is an admin
85+
'middleware_class' => \Backpack\Base\app\Http\Middleware\Admin::class,
86+
87+
// Alias for that middleware
88+
'middleware_key' => 'admin',
89+
// Note: It's recommended to use the backpack_middleware() helper everywhere, which pulls this key for you.
90+
8491
// What kind of avatar will you like to show to the user?
8592
// Default: gravatar (automatically use the gravatar for his email)
8693
// Other options:

src/helpers.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,18 @@ function backpack_avatar_url($user)
4242
}
4343
}
4444
}
45+
46+
if (!function_exists('backpack_middleware')) {
47+
/**
48+
* Return the key of the middleware used across Backpack.
49+
* That middleware checks if the visitor is an admin.
50+
*
51+
* @param $path
52+
*
53+
* @return string
54+
*/
55+
function backpack_middleware()
56+
{
57+
return config('backpack.base.middleware_key', 'admin');
58+
}
59+
}

0 commit comments

Comments
 (0)