Dear All, I have a problem like that.
// First, I created one to many relation for Post and PostCategory
// app/model/Post
public function post_category()
{
return $this->belongsTo('PostCategory');
}
// app/model/PostCategory
public function posts()
{
return $this->hasMany(Post);
}
// From my PostsController I can access properly for all Posts with category title
$data = Post::with('post_catgory')->get(); // this is fine
// But how can I grab data for single view? I tested like that.
$data = Post::find($id)->with('post_category')->get(); // doesn't work
$data = Post::find($id)->post_category; // doesn't work too.
Actually I don't know how to retrieve. Please help.
Post::with('post_category')->find($id);
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community