use Blade::if to check if a user is admin

This commit is contained in:
Pig Fang 2018-07-17 09:29:10 +08:00
parent 556f8268f3
commit 3df2f2dda9
3 changed files with 10 additions and 4 deletions

View File

@ -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();
});
}
}

View File

@ -18,7 +18,7 @@
<img src="{{ avatar($user, 128) }}" alt="User Image">
<p>{{ $user->email }}</p>
</li>
@if ($user->isAdmin())
@admin($user)
<!-- Menu Body -->
<li class="user-body">
<div class="row">
@ -34,7 +34,7 @@
</div>
</li>
<style>li.user-header { height: initial !important; }</style>
@endif
@endadmin
<!-- Menu Footer-->
<li class="user-footer">
<div class="pull-left">

View File

@ -68,10 +68,10 @@
<li class="header">{{ trans('general.explore') }}</li>
<li><a href="{{ url('skinlib') }}"><i class="fa fa-archive"></i> <span>{{ trans('general.skinlib') }}</span></a></li>
@if ($user->isAdmin())
@admin($user)
<li class="header">{{ trans('general.manage') }}</li>
<li><a href="{{ url('admin') }}"><i class="fa fa-cog"></i> <span>{{ trans('general.admin-panel') }}</span></a></li>
@endif
@endadmin
</ul><!-- /.sidebar-menu -->
</section>
<!-- /.sidebar -->