2

Is there known science for turning on Team Billing in Laravel Spark?

That is, if you want to use Laravel Spark's team billing features, you need to create your project with the team-billing option.

However, (hypothetically, he lied) if you didn't create your project with the --team-billing flag and suddenly needed the team billing features, is there a way to turn this on?

If not, is there a document list of the files you'd need to change?

I realize I could generate two new fresh projects, one with team billing and one without, and then diff the resulting projects to do this myself, but that seems an error prone route. I'd like to know if there's known science for this before heading down that path.

Alana Storm
  • 164,128
  • 91
  • 395
  • 599

3 Answers3

3

I investigated this one a bit on my own and have a solution that works as of July 14, 2017. This may change in a future Spark update, so YMMV. See below for the best way to check the difference between systems.

Enabling Team Billing

First, as mentioned elsewhere, you'll need to add the Laravel\Spark\CanJoinTeams trait to your App\User class.

#File: app/User.php
use Laravel\Spark\CanJoinTeams;
use Laravel\Spark\User as SparkUser;

class User extends SparkUser
{
    use CanJoinTeams;
    /* ... */
}

Second, you'll need to add team plans (instead of individual plans) in your spark provider. i.e. these defaults.

#File: app/Providers/SparkServiceProvider.php
public function booted()
{
    Spark::useStripe()->noCardUpFront()->trialDays(10);

    Spark::freePlan()
        ->features([
            'First', 'Second', 'Third'
        ]);

    Spark::plan('Basic', 'provider-id-1')
        ->price(10)
        ->features([
            'First', 'Second', 'Third'
        ]);
}

Need to be

public function booted()
{
    Spark::useStripe()->noCardUpFront()->teamTrialDays(10);

    Spark::freeTeamPlan()
        ->features([
            'First', 'Second', 'Third'
        ]);

    Spark::teamPlan('Basic', 'provider-id-1')
        ->price(10)
        ->features([
            'First', 'Second', 'Third'
        ]);
}

for team plans. Also, if it's not obvious, you can have both individual plans and team plans for a system at the same time.

Diff-ing Spark Versions

If you're coming here years later and you want to see what's needed in your version of Spark, here's the best way I found to do it.

First, create a Spark project with team billing

spark new project-name --team-billing

and then rename the project-name folder to something like with-team-billing

mv project-name with-team-billing

Then, do the same for a project without team billing

spark new project-name --team-billing    
mv project-name without-team-billing

Then, recursivly diff the two folders with your favorite diff commands

diff -r with-team-billing without-team-bill    
bbdiff with-team-billing without-team-bill    

Creating both projects with the same name is important, as a number of node/npm files get generated with cached file path values. They're irrelevant to our goals, and only clutter up the diff results.

Alana Storm
  • 164,128
  • 91
  • 395
  • 599
1

According to the docs (https://spark.laravel.com/docs/4.0/teams) all it requires is adding the trait Laravel\Spark\CanJoinTeams to your User model:

If you installed your application without the --team-billing flag but still want to enable teams later, you may simply add the Laravel\Spark\CanJoinTeams trait to your User model.

Marco Bamert
  • 196
  • 1
  • 1
    Thank you Marco -- +1 for the useful information. However -- some early research on the diff approach shows some changes in the SparkServiceProvider as well. It looks like those docs are incomplete, so I'm going to leave this open for a bit in case a more complete answer comes along. – Alana Storm Jul 13 '17 at 17:56
1

There is an open issue with people discussing this. As of this post, its possible but not very clean, and potentially error prone.

The general recommendation is to just start over with a new project with team billing enabled, then port over the code you need.

Samsquanch
  • 8,866
  • 12
  • 50
  • 89