2
votes

How to get the question by tag name or tag ID with Laravel, example like this page get the question by tag: Python

https://stackguides.com/questions/tagged/python

Example for my relationship:

post: id

tags: id

post_tag: post_id, tag_id

1
Tag is going to need a name, not just an ID value. - tadman

1 Answers

0
votes

Assuming your data structure (you should update with it):

By id

$my_tag_id = 1;
$my_posts = Post::where('tag_id',$my_tag_id )->get();

By name

$my_tag_name = 'python';
$my_posts = Post::where('tag_id',Tags::where('tag_name',$my_tag_name)->first()->id)->get();

Update with yours relationship and we can get a close approach