php - 方法 Illuminate\Database\Eloquent\Collection::__toString() 不得抛出异常
问题描述
我正在使用 Posgres,并且正在使用 mutator 来获取存储在 jsonb 列中的值。雄辩模型中的 mutator:
Anuncios.php (模型)
public function getStatusAttribute(){
if( $this->attributes['marketplace_id'] === 2)
{
$json_marketplace = json_decode( $this->attributes['json_anuncio_marketplace']);
return $json_marketplace->Code ;
}
}
但是从数据库中检索记录时出现以下错误, Anuncio::all();
方法 Illuminate\Database\Eloquent\Collection::__toString() 不能抛出异常,捕获 ErrorException: Trying to get property 'Code' of non-object
这是怎么回事?