0
我需要從屬性模型中提取所有圖像。 但我得到的是一個圖像集合,但我不知道如何訪問這些。Laravel 5從刀片系列中獲取屬性
下面是一些代碼:
PropertyController
public function show($id)
{
$property = Property::findOrFail($id);
$main_image = $property->images()->mainImage()->get();
$images = $property->images()->get();
return view('property.single',compact('property', 'images', 'main_image'));
}
我建立關係的性質和形象之間:
物業型號:
public function images()
{
return $this->hasMany('App\Image');
}
圖片型號:
public function property()
{
return $this->belongsTo('App\Property');
}
public function scopeMainImage($query)
{
$query->where('main_image', '=', 1);
}
我想到了一個{{$ main_image-> FILE_NAME}}做工作,但print_r的返回一些收集
[...]
[attributes:protected] => Array
(
[id] => 20
[property_id] => 25
[user_id] => 2
[file_name] => main_image.jpg
[file_type] => jpg
[file_url] => img/properties/25/main_image.jpg
[main_image] => 1
[created_at] => 2015-12-02 15:31:03
[updated_at] => 2015-12-02 15:31:03
)
[...]
那麼我能做些什麼來改變它來訪問這個集合?
謝謝!