Laravel 收银员 - Class "App\Models\User" 未找到
Laravel Cashier - Class "App\Models\User" not found
尝试取消与 Laravel 收银员的订阅时,returns 出现错误:
Class "App\Models\User" not found
代码:
public function cancel(Request $request) {
$subscription = Auth::user()->subscription('default');
$subscription->cancel();
}
这可能是因为我的用户模型不位于“App\Models\User”(Laravel 8 中的新默认值),而是位于“App\User”。
在官方文档中,是这样说的:
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.
但这不是问题所在。我的table名字是一样的,但是我的模型位置不同。
我该如何解决这个问题?
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);
}
尝试在 config/auth.php
中更改您的 providers
配置
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => App\User::class,
],
]
引用https://laravel.com/docs/8.x/authentication#the-user-provider-contract
尝试取消与 Laravel 收银员的订阅时,returns 出现错误:
Class "App\Models\User" not found
代码:
public function cancel(Request $request) {
$subscription = Auth::user()->subscription('default');
$subscription->cancel();
}
这可能是因为我的用户模型不位于“App\Models\User”(Laravel 8 中的新默认值),而是位于“App\User”。
在官方文档中,是这样说的:
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.
但这不是问题所在。我的table名字是一样的,但是我的模型位置不同。
我该如何解决这个问题?
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);
}
尝试在 config/auth.php
providers
配置
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => App\User::class,
],
]
引用https://laravel.com/docs/8.x/authentication#the-user-provider-contract