Answer the question
In order to leave comments, you need to log in
How to make a selection by tags?
standard structure. There are 2 tables: "POSTS" and "TAGS", as well as "POSTS_TAGS" linking them. And, accordingly, a page with a list of tags in the address bar is loaded. I just can't figure out how to implement a selection by these tags in Laravel. I am not very strong in SQL, so if anyone can help, I would be very grateful.
Answer the question
In order to leave comments, you need to log in
In the Tag model:
public function posts()
{
return $this->belongsToMany('App\Post', 'post_tag', 'tag_id', 'post_id');
}
https://laravel.com/docs/5.4/eloquent-relationship... I
recommend calling the table "post_tag", not "POSTS_TAGS".
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question