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

mikestratton's avatar

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.

0 likes
5 replies
Mick79's avatar

I have this same problem and I solved it by passing a "type" into the route.

So I have two routes that go to the same page

/register/customer

and

/register/agent

the route is

    Route::get('/register/{type}', 'MyRegisterController@index');

In the controller I then use that TYPE variable to split the journey.

mikestratton's avatar

Resolution #1:

The view for the controller is stored in the resources/views/vendor/spark/auth/register-common.blade.php blade template. From within that template it places a call to a function in the app.js file "plansForActiveInterval"

This js file calls to the sparkserviceprovider: boot function that has all of the stripe plans listed in it.

I created a function from within the app.js to call just the specific plans with a specific name and did not work.

I don't think editing the app.js is the correct solution for this.

mikestratton's avatar

Resolution #2

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?

mikestratton's avatar

Resolution #3

After adding the table 'user_role', subscriptions were no longer valid so Resolution #2 is not going to work. I am also concerned about the problems a Spark update would cause.

I used

git revert

to roll back to a previous commit and then merged my master branch with that branch.

mikestratton's avatar

@Mick79 Your answer was an incomplete, partial answer. A more extensive explanation of how to integrate with Spark would be useful.

Please or to participate in this conversation.