Skip to content

Instantly share code, notes, and snippets.

@EricBusch
Forked from dillinghamio/@plan.md
Last active November 15, 2017 20:09
Show Gist options
  • Save EricBusch/6cf1d5402f30840aeb7526e6d9110f72 to your computer and use it in GitHub Desktop.
Save EricBusch/6cf1d5402f30840aeb7526e6d9110f72 to your computer and use it in GitHub Desktop.
Laravel Spark @plan Blade Directive - Create new Blade Directive (conditional)

@plan Blade Directive For Laravel Spark

Works with user & team billing

Add this to the boot() method of your AppServiceProvider

\Blade::directive('plan', function($plans) {

        $model = auth()->user();

        if(\Spark::usesTeams())
        {
            $model = $model->currentTeam();
        }

        $activePlan = $model->sparkPlan()->id;

        return "<?php if((is_array(with{$plans})) ? in_array('$activePlan', with{$plans}) : with{$plans} == '$activePlan') : ?>";
});

\Blade::directive('endplan', function() {

        return "<?php endif; ?>";
});

And use like so

@plan('free')
    <h1>Free</h1>
@endplan

@plan('provider-id-1')
    <h1>Plan 1</h1>
@endplan

@plan('provider-id-2')
    <h1>Plan 2</h1>
@endplan

Can also pass an array

@plan(['provider-id-1', 'provider-id-2'])
    <h1>Plan 1 or Plan 2</h1>
@endplan

See also @role Blade Directive For Laravel Spark

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