Laravel Spark


September 16th, 2015


Please Note: This article was written when the Alpha version of Spark first released. It is no longer accurate as Spark is now a commercial project. Have a look at this Laravel Spark article for the new version.

The Alpha of Laravel Spark has just been released and its goal is to be an opinionated way of building out business oriented SaaS applications. It features team management, user roles, recurring billing through Stripe, and much more. In this tutorial let’s take a deeper look at this new package.

Spark is designed with only one goal in mind, to make scaffolding out a billing system for a SaaS app easy. If you’ve ever built out team management and a billing system then you already know how time-consuming and painful this process is. There is so much tedious work hooking up all the different systems, designing it, creating invoices, and on and on. By using Spark, you can put your focus on what matters, the business.

So let’s jump in and take a first look at Laravel Spark.

Please note that Spark is an ALPHA release. Things will change and things will break. This post is meant to give you an overview of what it features right now. As Spark stabilizes I will update this post as appropriate.

Spark Installation

The installation of Spark is straightforward by utilizing a global composer package that does all the heavy lifting. To install this open your terminal and type in:

1composer global require "laravel/spark-installer=~1.0"

Next, either create a new Laravel app or go inside your existing and run:

1spark install

Once this runs it will ask you a few questions from the console:

![Spark Install](
Spark Install
As you can see it tells you everything you need and will run all the commands for you. Of course, you can always run these commands manually with:
  • php artisan migrate
  • npm install
  • gulp

At the end of the install, it warns you to setup your Stripe tokens and an Authy key in your .env file. Authy is a two-factor authentication (2FA) system for protecting logins and you can signup for a free API key.

Now with the basic install completed let’s dive into setting it up.


The SparkServiceProvider handles a lot of the settings for Spark and is really powerful. Open the file and let’s go through each major section covering the basic details on what it does.


The invoiceWith is used when generating email invoices for customers:

1protected $invoiceWith = [
2 'vendor' => 'Your Company',
3 'product' => 'Your Product',
4 'street' => 'PO Box 111',
5 'location' => 'Your Town, 12345',
6 'phone' => '555-555-5555',

This will be one of the first things you change and should be pretty self-explanatory.

customizeSpark Method

By default all this method does is register the team model:

2 'models' => [
3 'teams' => Team::class,
4 ]

You can add other configuration, change the team model, and more.

Customize Registration and Profile Updates

The customizeRegistration and customizeProfileUpdates methods are designed to add new validation rules to these forms and/or to adjust the way users are saved. This allows you to do any custom processing.

Customize Roles

The customizeRoles integrates with Laravel 5.1.11’s new authorization feature. You can set a default role:


Plus add your own roles:

2 'admin' => 'Administrator',
3 'member' => 'Member',

Customize Settings Tabs

The customizeSettingsTabs allows you to add or remove new links in the settings forms. For example, the member settings looks like this:

![Spark Default Settings](
Spark Default Settings
Now, if you want to add a new link you can do so by “making” a new tab under the current list:
1Spark::settingsTabs()->configure(function ($tabs) {
2 return [
3 $tabs->profile(),
4 $tabs->teams(),
5 $tabs->security(),
6 $tabs->subscription(),
7 $tabs->make('My New Setting', 'test', 'fa-rocket'),
8 ];

The order of parameters of $tabs->make is title, view file, icon. So in my example, I named the link “My New Setting”, created a new blade file at resources/views/test.blade.php, and used the fa-rocket icon from FontAwesome.

![New Link Added to Spark Settings](
New Link Added to Spark Settings
You can also do the same for the tabs on the team settings page as well. It follows the same format.

Building Spark Subscription Payment Plans

Locate the customizeSubscriptionPlans method and adjust the plans to match your business needs. In this example, I created two plans with 10-day trials, that can also be purchased yearly:

1Spark::plan('Basic', 'stripe-id')->price(10)
2 ->features([
3 'Feature 1',
4 ]);
5Spark::plan('Advanced', 'stripe-id')->price(40)
6 ->trialDays(7)
7 ->features([
8 'Feature 1',
9 'Feature 2',
10 ]);
12Spark::plan('Basic', 'stripe-id')->price(10)
13 ->yearly()
14 ->features([
15 'Feature 1',
16 ]);
17Spark::plan('Advanced', 'stripe-id')->price(40)
18 ->yearly()
19 ->features([
20 'Feature 1',
21 'Feature 2',
22 ]);

Spark really shines with the visual representation of these plans. When I added a yearly plan. The UI changed with a button to swap between monthly and yearly:

![Spark Plans](
Spark Plans
Before a purchase can be made you will need to edit the ‘stripe-id’ and insert a real one.

Coupons and Discounts

No order system would be complete without the ability to offer customers coupons and discounts. Spark enables this in two ways.

The first is by coupons. Inside Stripe create a new one and then send your user to the register page like this:


Once Spark sees the coupon in the GET request it will automatically validate it from the Stripe API and apply the discount amount to the total.

![Spark Coupon Applied](
Spark Coupon Applied
Site wide discounts work much the same way. The only difference is you define it in the Spark Service Provider. Inside boot() or customizeSpark() add the following:

Now that discount will be applied to any order.

Terms & Conditions

Create a new file named in the root of your install and it will automatically be pulled in for the /terms route. The markdown parsing is handled by Parsedown.


Spark is opinionated but very powerful. The next time you need to setup recurring billing I would recommend giving Spark a try. It will save you tons of time and effort.

Please note that Spark is an ALPHA release. Things will change and things will break. This post is meant to give you an overview of what it features right now. As Spark stabilizes I will update this post as appropriate.

Filed in:

Eric L. Barnes

Eric is the creator of Laravel News and has been covering Laravel since 2012.

Laravel News Partners