I have tree tables in my database (Posts Tags Post_tag(pivot table)):
- Posts(id,content,title,...)
- Tags(id,tag_name)
- post_tag(id,post_id,tag_id)
Now my problem is about how can I select all posts with same tags to an post for example: select all posts that have similar tags as post 1. I have create the relationships between the posts and tags tables: In posts table:
public function tags(){
return $this->belongsToMany('App\Tag');}
In tags table:
public function posts(){
return $this->belongsToMany('App\Post');}
from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/1php1I6
via IFTTT
Aucun commentaire:
Enregistrer un commentaire