How to get the question by tag name or tag ID with Laravel, example like this page get the question by tag: Python
https://stackoverflow.com/questions/tagged/python
Example for my relationship:
post: id
tags: id
post_tag: post_id, tag_id
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.