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.
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.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community