Home > Mobile >  Laravel Cashier - Class "App\Models\User" not found
Laravel Cashier - Class "App\Models\User" not found

Time:11-18

When trying to cancel a subscription with Laravel Cashier, it returns the error:

Class "App\Models\User" not found

Code:

public function cancel(Request $request) {
    $subscription = Auth::user()->subscription('default');
    $subscription->cancel();

This is likely because my user model is not located at "App\Models\User" (the new default in Laravel 8), but rather it is located at "App\User".

In the official documents, it mentions this:

If you're using a model other than Laravel's supplied App\Models\User model, you'll need to publish and alter the Cashier migrations provided to match your alternative model's table name.

But this isn't the problem. My table name is the same, but the location of my model is different.

How do I fix this?

CodePudding user response:

use App\User; // this is important in your case
use Laravel\Cashier\Cashier;

/**
 * Bootstrap any application services.
 *
 * @return void
 */
public function boot()
{
    Cashier::useCustomerModel(User::class);
}

Docs: https://laravel.com/docs/8.x/billing#billable-model

CodePudding user response:

Try change your providers config in config/auth.php

'providers' => [
  'users' => [
    'driver' => 'eloquent',
    'model' => App\User::class,
  ],
]

Reference https://laravel.com/docs/8.x/authentication#the-user-provider-contract

  • Related