Hello, from the conversation on IRC, I concluded this could work:
$posts = Topic::where('slug', '=', $topic_slug)->posts()->take(5)->get();
assuming function posts() has many Post
Thanks delmadord,
That produced an method not found exception. Adding ->first()
made it work. Final query:
$posts = Topic::where('slug', '=', $topic_slug)->first()->posts()->take(5)->get();
Fixed.
Nice to hear that.
Note that if there are no Topics matching given slug, FatalErrorException Call to a member function posts() on a non-object
happens, you can thus modify your query to
$posts = Topic::where('slug', '=', $topic_slug)->firstOrFail()->posts()->take(5)->get();
Have a nice day.
That's right :)
Awesome stuff - thanks again.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community