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

mikestratton's avatar

Spark: Multiple Registration Forms for Different User/Subscription Types

When a user registers, Laravel Spark uses the plans listed in the sparkserviceprovider.php booted() function and passes these plans to the registration form.

I have two separate user types: consumer and business. I have Stripe subscription plans for both user types that work using the default registration form.

I need to separate these registration forms so that when a consumer clicks signup he will see only the consumer plan in his registration form. Likewise for a business subscription/registration form.

Resolution

In the spark/src/Plan.php file I added the variable:

public $userRole;  

I then appended:

 public function __construct($name, $id, $userRole)
    {
        $this->id = $id;
        $this->name = $name;
        $this->userRole = $userRole;
    }

and

  public function jsonSerialize()
    {
        return [
            'id' => $this->id,
            'name' => $this->name,
            'userRole' => $this->userRole,
            'price' => $this->price,
            'trialDays' => $this->trialDays,
            'interval' => $this->interval,
            'features' => $this->features,
            'active' => $this->active,
            'attributes' => $this->attributes,
            'type' => $this->type,
        ];
    }  

In the spark/src/Configuration/ManageAvailablePlans.php file, I appended:

 public static function plan($name, $id, $userRole)
    {
        static::$plans[] = $plan = new Plan($name, $id, $userRole);

        return $plan;
    }

In the app/Providers/SparkServiceProvider.php file, I made sure to pass three parameters:

Spark::plan('Supplier', 'your_stripe_id_01', 'seller')
            ->price(29.99)
            ->trialDays(10)  

Spark::plan('Ecommerce User', your_stripe_id_02', 'buyer')
            ->price(9.99)
            ->trialDays(10)
          

In the spark migration: _create_subscriptions_table.php, I added the table:

$table->string('user_role');  

I then changed the migration table in mysql so that the batch table for the subscriptions migration was the highest number. I then ran:

php artisan migrate:rollback
php artisan migrate

Everything worked above without error. I believe the next step is to get a better understanding of vue.js and how it is serving data to the blade.php files.

Feedback, please?

0 likes
2 replies
nerginer's avatar

Thanks for the great info. It mostly apply to spark v4 but there is some minor changes. Did you update this to spark v4. If so please share with us. If not can you guide me to change the plan function which is now in src/SparkManager

public function plan($billableType, $name, $id)

what is the billableType?

nerginer's avatar

I found that it is 'user'

Is it possible to add plan by defining it in the SparkServiceProvider according to a user field.

ex: If Auth::User->department = "finance" { Spark::plan('user','Nuri Plan', 'price_xxx) ->shortDescription('Nuri short desc') ->features(['All benefits included']); }

Please or to participate in this conversation.