@roles
Blade Directive For Laravel Spark
Assumes you're using teams
Add this to the boot()
method of your AppServiceProvider
\Blade::directive('role', function($role) {
$user = auth()->user();
$roleOn = $user->roleOn($user->currentTeam);
$rolesToLook = explode(',', str_replace(array("'", '(', ')', ' '), "", $roles)); // make an array out of the weird strig we get
$show = in_array($roleOn, $rolesToLook);
if ($show) {
return "<?php if(true) : ?>";
}
return "<?php if(false) : ?>";
});
\Blade::directive('endrole', function($plan_id) {
return "<?php endif; ?>";
});
And use like so
@roles('owner')
<h1>Owner</h1>
@endrole
@roles('member', 'VIP')
<h1>Member or VIP</h1>
@endrole