Support the ongoing development of Laravel.io →
Database Eloquent
Last updated 2 years ago.
0

Probabily this would be better:

$articles = Tag::where('name', $tag)->articles()->paginate(15);

You have to define the inverse of many to many relationships to tag Model too.

0

Thank you for answering :) QueryBuilder has no relational function and outputted an error, so I tried to use "with" like this

$articles = Tag::where('name', $tag)->with('articles')->paginate(15);

Giving $tag, at first only one article of three articles which have the same name as $tag was appeared, but article's object has invalid property and program would be crashed when I tried to view.

Last updated 8 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Kunimaru kunimaru Joined 30 Jul 2016

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.