我有模型Post的属性:id, content, image, publish_date
。在Post模型中,我可以获得所有属性但使用$this->$attr
时的图像,它在调用$ this-> image时显示Undefined属性。我不知道为什么。但是当我打电话给Controller: Post::find(1)->image
时,它运作正常。任何人都可以帮我吗?
由于您使用的是accessor,请尝试这样做:
public function getImageAttribute($value)
{
dd($value);
}