在控制器中覆盖Laravel Model get方法

时间:2018-04-24 11:43:00

标签: php laravel

有没有办法在控制器中覆盖Model get方法? “我的管理”面板使用属性的get方法,但对于前端,我希望它具有不同的功能,而无需更改属性名称或添加新属性。

让我们说这是我在模型中完成前端所需要的:

    public function getImagesAttribute()
{
    if ($this->attributes['thumbnail']) {
        $images = array($this->attributes['images']);
        $images[] = $this->attributes['thumbnail'];
        return $images;
    }
    return $this->attributes['images'];
}

但是这会将缩略图显示为管理面板内的图像,这完全不同。

1 个答案:

答案 0 :(得分:0)

image view
相关问题