Search code examples
phplaravelstripe-paymentslaravel-cashier

Why does php migration keeps on creating columns on default cashier model (User) even changed to different model


I would like to change the default cashier's model to my custom model (Users to Companies)

What i have done is

  1. changed the services.php's model to App\Models\Companies\Companies::class
  2. changed my .env's to CASHIER_MODEL=App\Models\Companies\Companies
  3. published the cashier migration and alter the table name to companies but

php artisan migrate will still update cashier's default model that is Users

// services.php
    'stripe' => [
            'model' => App\Models\Companies\Companies::class,
            'key' => env('STRIPE_KEY'),
            'secret' => env('STRIPE_SECRET'),
            'webhook' => [
                'secret' => env('STRIPE_WEBHOOK_SECRET'),
                'tolerance' => env('STRIPE_WEBHOOK_TOLERANCE', 300),
            ],
        ],

CASHIER_MODEL=App\Models\Companies\Companies  // on .env


// on migration
    public function up()
    {
        Schema::table('companies', function (Blueprint $table) {
            $table->string('stripe_id')->nullable()->collation('utf8mb4_bin')->index();
            $table->string('card_brand')->nullable();
            $table->string('card_last_four', 4)->nullable();
            $table->timestamp('trial_ends_at')->nullable();
        });
    }

Solution

  • Laravel keeps loading the Cashier migrations from the vendor folder even if you have published them to the database/migrations folder and edited them.

    The solution is to explicitly tell Laravel to ignore the vendor migrations.

    Add the following to the register method of the AppServiceProvider:

    // Use the Cashier migrations from migration folder instead of vendor folder
    Cashier::ignoreMigrations();
    

    Remember to also include:

    use Laravel\Cashier\Cashier;