@role
Blade Directive For Laravel Spark
Assumes you're using teams
Add this to the boot()
method of your AppServiceProvider
\Blade::directive('role', function($roles) {
$user = auth()->user();
$userRole = $user->roleOn($user->currentTeam);
return "<?php if((is_array(with{$roles})) ? in_array('$userRole', with{$roles}) : with{$roles} == '$userRole') : ?>";
});
\Blade::directive('endrole', function() {
return "<?php endif; ?>";
});
And use like so
@role('owner')
<h1>Owner</h1>
@endrole
@role('member')
<h1>Member</h1>
@endrole
Can also pass an array of multiple roles
@role(['member', 'owner'])
<h1>Member or Owner</h1>
@endrole
Any particular reason for the inclusion of
$plan_id
for theendrole
directive?