@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
@dillinghamio
It does not work! What's
with{$plan}
is doing insidein_array
?Also what if user is not logged in??
I used a helper and it works like a charm: