Build a Monthly Subscription App with Laravel Cashier

Cashier Setup

Installing Laravel Cashier requires four main steps.

Install Cashier using Composer

composer require laravel/cashier

Create the migrations

php artisan make:migration add_cashier_fields_to_users_table --table=users
php artisan make:migration create_subscriptions_table --create=subscriptions

And the migration fields:

Schema::table('users', function ($table) {
    $table->string('stripe_id')->nullable();
    $table->string('card_brand')->nullable();
    $table->string('card_last_four')->nullable();
    $table->timestamp('trial_ends_at')->nullable();
});

Schema::create('subscriptions', function ($table) {
    $table->increments('id');
    $table->integer('user_id');
    $table->string('name');
    $table->string('stripe_id');
    $table->string('stripe_plan');
    $table->integer('quantity');
    $table->timestamp('trial_ends_at')->nullable();
    $table->timestamp('ends_at')->nullable();
    $table->timestamps();
});

Attach the Billable trait to the User Model

In app/User.php:

use Laravel\Cashier\Billable;

class User extends Authenticatable {

    use Billable;

}