DEV Community

Tim Bogdanov
Tim Bogdanov

Posted on

Setting up Laravel Cashier (Managing Subscriptions)

  1. Install the Laravel Cashier package by running composer require laravel/cashier in your terminal.

  2. Add the Laravel\Cashier\CashierServiceProvider::class to the providers array in your config/app.php file.

  3. Run the php artisan vendor:publish --provider="Laravel\Cashier\CashierServiceProvider" command to publish the package's configuration file to your application.

  4. Add the Billable trait to your user model, which will give your users the ability to manage their subscriptions.

  5. Add the necessary columns to your users table by running the php artisan migrate command.

  6. In your user model, define a plan attribute that specifies the name of the subscription plan your users can subscribe to.

  7. In your application's subscription logic, you can use Laravel Cashier's methods to create subscriptions, manage plans, and handle billing. For example, you can use the subscription() method to retrieve the user's current subscription, and the newSubscription() method to create a new subscription for the user.

I hope this helps! Let me know if you have any other questions.

Top comments (0)