Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/252.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Laravel 5.1带有路径的图像上的查询镜或访问器_Php_Laravel_Laravel 5 - Fatal编程技术网

Php Laravel 5.1带有路径的图像上的查询镜或访问器

Php Laravel 5.1带有路径的图像上的查询镜或访问器,php,laravel,laravel-5,Php,Laravel,Laravel 5,我现在被什么东西卡住了。现在我有一个广告控制器,它有很多图像 class Ad extends Model { public function images() { return $this->hasMany('Core\Entities\Ad\AdImages', 'ad_id', 'id')->orderBy('img_is_default', 'desc'); } } images表中有一列表示图像名称(例如my.jpg),另一列表示图像路径i

我现在被什么东西卡住了。现在我有一个广告控制器,它有很多图像

class Ad extends Model
{
   public function images()
   {
       return $this->hasMany('Core\Entities\Ad\AdImages', 'ad_id', 'id')->orderBy('img_is_default', 'desc');
   }
}
images表中有一列表示图像名称(例如my.jpg),另一列表示图像路径img\u路径(例如“
custom/folder/images/date
”)

这里的问题或麻烦是,当我在视图中循环出图像时,我还必须添加
$result->image\u path./.$result->image\u name

有人知道我如何像查询镜一样将图像路径和图像名称合并成一个图像吗

基本上,我只想像
$result->primaryImage()
那样,然后输出
custom/folder/images/date/myimage.jpg

^已经格式化了


这可能吗?

您可以使用访问器

class AdImage ....
{
    public function getFullPathAttribute()
    {
        return $this->attributes['image_path'] .'/'. $this->attributes['image_name'];
    }
}

$img->full_path; // the combined value from above

您甚至可以通过执行以下操作来缩短此操作:
返回$this->image\u path./'.$this->image\u name;