【发布时间】:2020-07-01 06:53:43
【问题描述】:
我在我的模型中使用方法来改变对我的客户的单个响应
什么时候默认使用这个方法名调用产品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':
我该如何解决这个错误?
【问题讨论】:
标签: php laravel debugging eloquent laravel-7.x