Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

jh's avatar
Level 1

Only showing eligible plans on the subscription page

My application has two pricing tiers. The regular, and a lower rate for a few special people that I set manually. This is accomplished with a "tier" column in the users table, 0 is a regular customer and 1 is the lower rate. I have this technically working with the checkPlanEligibilityUsing feature like so:

Spark::checkPlanEligibilityUsing(function($customer, $plan) {
    $tierMap = [
        'plan1-standard' => 0,
        'plan2-standard' => 0,
        'plan3-standard' => 0,
        'plan1-vip' => 1,
        'plan2-vip' => 1,
        'plan3-vip' => 1,
    ];
    
    return $tierMap[$plan->id] === $customer->tier;
});

But of course, all six plans are visible on the subscription page. While I could probably hack something together on my own, I'd like to know what "the Spark way" of going about this is so while building, I have the right ideas. How can I ensure customers only see plans that match their tier?

Registration page is not relevant, users are something only I add.

Cheers

0 likes
2 replies
EventFellows's avatar

I'd suggest to use '->attributes('key' => 'value')' on the Spark:: plan() in SparkServiceProvider to set your values and then filter based on it. You'd probably need a logged in user then to differentiate.

rimadiahw's avatar

when i try checkPlanEligibilityUsing(),but i get error 'Call to undefined method'. what should i do to resolve this problem? thanks

Please or to participate in this conversation.