简体   繁体   English

Laravel从关系中获取数据

[英]Laravel get data from relationship

How to get the question by tag name or tag ID with Laravel, example like this page get the question by tag: Python 如何使用Laravel通过标签名或标签ID来获取问题,例如此页面的示例通过标签来获取问题:Python

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

Example for my relationship: 我的关系的例子:

post: id 帖子:id

tags: id 标签:id

post_tag: post_id, tag_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 更新您的恋爱关系,我们可以采取更紧密的联系

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM