【发布时间】:2015-03-18 16:57:51
【问题描述】:
让我告诉你我有什么。
//Post Controller
public function showPost(Post $post)
{
$albums = $post->album()->with('photos')->get();
$comments = $post->comments()->where('approved', '=', 1)->get();
$this->layout->title = $post->title;
$this->layout->main = View::make('home')->nest('content','posts.single', compact('post', 'comments','albums'));
}
mysql语句执行正确
string 'select * from albums where albums.id = '{"id":19,"title":"Post no 19","read_more":"Lorem i'... (长度=786)
字符串'从albums中选择*,其中albums.post_id ='19''(长度=54)
string 'select * from images where images.album_id in ('4')' (length=57)
我想访问刀片中的照片对象,所有内容都解析为模板,但是当我尝试获取照片时
@foreach($albums->照片为 $photo)
未定义属性:Illuminate\Database\Eloquent\Collection::$Photos(查看:
//发布模型
public function album()
{
return $this->hasOne('Album');
}
//专辑型号
public function Photos(){
return $this->hasMany('Image');
}
【问题讨论】:
标签: laravel