Error: Object of class App\Http\Resources\ProductAttributeResource could not be converted to int

Error: Object of class App\Http\Resources\ProductAttributeResource could not be converted to int

我在我的模型中使用方法来改变对我的客户的单一响应

调用产品Laravel时默认使用这个方法名?

/**
 * Returns product attributes data to use in the API response.
 *
 * @return \Illuminate\Http\Resources\Json\AnonymousResourceCollection
 */
public function getAttributes()
{
    return ProductAttributeResource::collection($this->attributes);
}

调试器显示这个区域:

C:\xampp\htdocs.../...\vendor\Laravel\framework\src\Illuminate\Database\Eloquent\Concerns\HasAttributes.php:521

protected function castAttribute($key, $value)

{
    $castType = $this->getCastType($key);

    if (is_null($value) && in_array($castType, static::$primitiveCastTypes)) {
        return $value;
    }
    switch ($castType) {
        case 'int':
        case 'integer':
            return (int) $value;
        case 'real':

我该如何解决这个错误?

在我的例子中,我在我的模型中使用了一个保留的方法名称

例如,我为我的一对多关系定义了一个新的 attribute() 方法,我应该为它选择另一个名称

只需要将模型中的 getAttributes 方法重命名为 getAttribute 方法

因为这个名字被模特使用Class