【问题标题】:Class 'App/User' not found in file .... WebhookController.php on line 208 Laravel Cashier Stripe Webhook在文件中找不到类 'App/User' .... 第 208 行的 WebhookController.php Laravel Cashier Stripe Webhook
【发布时间】:2020-01-02 01:03:12
【问题描述】:

这是我的 Webhook 控制器中显示错误的部分。一切对我来说都是正确的。我可能会错过什么?

此外,只有处理付款发票 webhook 有效,其他一切都给我下面的 500 错误。

  /**
 * Get the billable entity instance by Stripe ID.
 *
 * @param  string|null  $stripeId
 * @return \Laravel\Cashier\Billable|null
 */
protected function getUserByStripeId($stripeId)
{
    if ($stripeId === null) {
        return;
    }

    $model = config('cashier.model');

    return (new $model)->where('stripe_id', $stripeId)->first();

}

这是我在尝试测试条带 Webhook 时遇到的 500 错误。

Test webhook error: 500

Symfony\Component\Debug\Exception\FatalThrowableError: Class 'App/User' not found in file /.../vendor/laravel/cashier/src/Http/Controllers/StripeWebhookController.php on line 208

我的用户文件在 App\User 中。她是我的用户档案

class User extends Authenticatable
{

use Notifiable, Billable;


protected $connection = 'mongodb';


/**
 * The attributes that are mass assignable.
 *
 * @var array
 */
protected $fillable = [
    'name', 'email', 'username', 'password', 'phone',
];
/**
* The collection name
*
* @var array
*/
protected $collection = 'users';

/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $dates = ['deleted_at'];
/**
 * The attributes that should be hidden for arrays.
 *
 * @var array
 */
protected $hidden = [
    'password', 'remember_token',
];

/**
 * The attributes that should be cast to native types.
 *
 * @var array
 */
protected $casts = [
    'email_verified_at' => 'datetime',
];

}

这是我的配置\auth.php

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

【问题讨论】:

  • 这听起来像是 Laravel 错误:stackoverflow.com/questions/35821477/…
  • 请检查命名空间下和顶部是否有代码'use App\User'。
  • 你的用户模型的命名空间是什么,你有没有将你的用户模型导入这个类?回答这两个问题应该可以解决您的问题。
  • @PrafullaKumarSahu 我的 User 模型的命名空间是,命名空间 App;如何将用户模型导入此类?谢谢
  • @rohit 我有'使用 App\User;'命名空间下。谢谢。

标签: php laravel laravel-cashier


【解决方案1】:

请检查您的 config/auth.php 文件并查找此代码

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

检查您的模型是位于 app 文件夹还是 app\Models 中?如果它在模型文件夹中,则将App\User 更改为App\Models\User

如果不起作用,请尝试使用以下命令清除缓存:

php artisan config:cache
php artisan config:clear

【讨论】:

  • 我的 config/auth.php 配置正确,App\User 位于正确的位置。我还运行了“php artisan config:cache”和“php artisan config:clear”命令,不幸的是我仍然收到错误消息。谢谢。
猜你喜欢
  • 2021-12-28
  • 1970-01-01
  • 2015-04-18
  • 1970-01-01
  • 1970-01-01
  • 2016-07-26
  • 2017-06-07
  • 2017-10-04
  • 2021-05-04
相关资源
最近更新 更多