From 3df2f2dda9a8f5898e1458ca8dc0f11724a70158 Mon Sep 17 00:00:00 2001 From: Pig Fang Date: Tue, 17 Jul 2018 09:29:10 +0800 Subject: [PATCH] use `Blade::if` to check if a user is admin --- app/Providers/AppServiceProvider.php | 6 ++++++ resources/views/common/user-menu.tpl | 4 ++-- resources/views/user/master.tpl | 4 ++-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index c9c5d3b7..73fb0272 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -2,9 +2,11 @@ namespace App\Providers; +use Blade; use Event; use Utils; use App\Events; +use App\Models\User; use Illuminate\Support\ServiceProvider; class AppServiceProvider extends ServiceProvider @@ -61,5 +63,9 @@ class AppServiceProvider extends ServiceProvider $this->app->singleton('users', \App\Services\Repositories\UserRepository::class); $this->app->singleton('parsedown', \Parsedown::class); + + Blade::if('admin', function (User $user) { + return $user->isAdmin(); + }); } } diff --git a/resources/views/common/user-menu.tpl b/resources/views/common/user-menu.tpl index b460f14f..907469a3 100644 --- a/resources/views/common/user-menu.tpl +++ b/resources/views/common/user-menu.tpl @@ -18,7 +18,7 @@ User Image

{{ $user->email }}

- @if ($user->isAdmin()) + @admin($user)
  • @@ -34,7 +34,7 @@
  • - @endif + @endadmin
  • {{ trans('general.explore') }}
  • {{ trans('general.skinlib') }}
  • - @if ($user->isAdmin()) + @admin($user)
  • {{ trans('general.manage') }}
  • {{ trans('general.admin-panel') }}
  • - @endif + @endadmin