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

jlmmns's avatar
Level 12

How does Spark make this closure work?

Spark has an interaction to constrain access to a user's plan, like this:

Spark::checkPlanEligibilityUsing(function ($user, $plan) {
    if ($plan->name == 'pro' && count($user->todos) > 20) {
        return false;
    }
});

https://spark.laravel.com/docs/3.0/billing#constraining-access-to-plans

I want to implement a similar feature, but I'm at a loss as to how Spark/Laravel automatically resolves the current $user and $plan into that closure.

Could anyone clear this up for me?

I guess I need to know how you register closures in general.

Thanks!

0 likes
0 replies

Please or to participate in this conversation.