Skip to content

Instantly share code, notes, and snippets.

@jpmurray
Forked from dillinghamio/@role.md
Last active May 17, 2020 14:54
Show Gist options
  • Save jpmurray/ea12b3527756d710df9d4ca996a4ae47 to your computer and use it in GitHub Desktop.
Save jpmurray/ea12b3527756d710df9d4ca996a4ae47 to your computer and use it in GitHub Desktop.
@roles Blade Directive For Laravel Spark

@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

Based @role.md. Find More Awesome Spark Stuff Here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment