در حال بارگذاری ...

Introducing Team Billing0:00

Hi, this is Taylor Otwell, back with another Laravel screencast. And in this screencast, I want to show you team billing in Laravel Spark. Now, in the previous screencast, I showed you user billing. But you can actually configure Spark to bill individual teams. So a User can have multiple teams that are all on different billing plans. Kind of like GitHub organizations. So, to get started, let's go ahead and configure some team plans. Now, when you first install Spark, you can actually install Spark with a team billing flag. So when I first install Spark, I can do spark new demo --team-billing. But I didn't initialize this project in that way.

Enabling Team Billing0:31

So when I first install Spark, I can do spark new demo team billing. But I didn't initialize this project in that way. So I'm going to show you how I'm going to just manually enable team billing. Alright, so let's jump into our code. And first, let's go to the User model. And we're going to use the canJoinTeams trait. So I'm going to import Laravel\Spark\canJoinTeams. And I'm just going to use that trait right there. And that will bring in some team-related methods into our User model. Now I just need to go to my SparkServiceProvider.

Configuring Team Plans1:00

And that will bring in some team-related methods into our User model. Now I just need to go to my SparkServiceProvider. And instead of saying plan, I'm just going to say teamPlan. Alright, and let's go ahead and add a second proPlan here. So let's add a second proPlan for $20 a month. And this is SparkTest2. And this is going to be SparkTest1 because that's how I have them configured in Stripe. Now we also need to update this trialDays method call. And we need to change that to teamTrialDays. And that's just going to say we want every team that is created to have an automatic free trial of 10 days with no credit card up front.

Updating Routes Middleware1:31

And we need to change that to teamTrialDays. And that's just going to say we want every Team that is created to have an automatic free trial of 10 days with no credit card up front. Alright, and now we do also need to come into our routes file. Now if you look at this HomeController, which is the dashboard for our application, you can see that I've added a subscribed middleware here. And what that means is they can't access the dashboard of this application unless they're actually a subscribed user. And now what we mean by subscribed is they're either on a trial, they have an active subscription, or they're still within their grace period after canceling their subscription. Alright, now this checks that the individual user is subscribed. So I'm going to check this to teamSubscribed.

Registering With Team2:10

Alright, now this checks that the individual User is subscribed. So I'm going to check this to teamSubscribed. And that's going to make sure that the current team is actually subscribed to Spark, not necessarily the individual User. Alright, so let's go ahead and dive into this. Now I think this should be all we need to do. We've imported the trait onto our User, we've updated our SparkServiceProvider, and we're using the teamSubscribed middleware. So let's go ahead and create an account on our application. Now you can see on this screen I have an additional field here compared to previous screencasts, and that's the team name field.

Now you can see on this screen I have an additional field here compared to previous screencasts, and that's the team name field. Spark will actually not let me register for the application without creating a team when teams are enabled. So let's go ahead and enter this information and register for our application. Now when I create this, it's actually going to create my User, of course, but then also create the team and assign me as the owner of the team. Alright, so now I'm subscribed. And what's really cool is if I go to this dropdown, I can see a list of my current teams and see that Laravel is the team that I'm currently viewing. Alright, let's go ahead and create another team so we can take a look at what this looks like if you have more than one team.

and see that Laravel is the team that I'm currently viewing. Alright, let's go ahead and create another team so we can take a look at what this looks like if you have more than one team. Let's create a second team here. Let's call it Laracast. And I've created that team, and now if I go back to my dashboard, you can see that I have two teams, and I can click one to switch in between them. And what that means is that's going to change the current team variable that's available in my User model and in my JavaScript that I know what kind of information do I need to pull for this dashboard. Is it the information for the Laracast team? For instance, the to-do list for the Laracast team or the to-do list for the Laravel team?

Subscribing a Team4:17

So within this screen, I can subscribe the team to a given plan. Alright, so let's subscribe the Laravel team to the basic plan. Just like on the individual user subscription screen, it has all the same information here. So I'll enter my test credit card number and subscribe this team to the application. And now each team can have, of course, separate credit card information, be on separate plans, and has separate invoices. So they're entirely distinct build entities, just like GitHub organizations. Alright, so that's teams and how you set up team building in Laravel Spark.

دوست دارید گاهی خبرهای Laracasts را ایمیل کنیم؟