D
D
Dmitry Kuznetsov2017-09-06 13:43:08
MySQL
Dmitry Kuznetsov, 2017-09-06 13:43:08

How to implement multicategories in news?

I am finishing the news module on the site. It is necessary to make it possible to add several categories to the news.
There are 2 tables:

The news itself
e5c87dc31ad14716ba91b81c385d999e.png

category table
b5a3f58eab034dbc81ef5d51af8038a1.png

Through laravel I get the following data:
public static function getNews(){
        $getNews = News::where('status_news', 1)
                        ->orderBy('id_news', 'desc')
                        ->join('users', 'author_news', '=', 'id_users')
                        ->join('category', 'id_category', '=', 'category_news')
                        ->paginate(3);

        return $getNews;
    }

But this query does not take into account multicategories. So how do you do it right? It is desirable if you do not need to change the table. Thanks in advance!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2017-09-06
@NeiroNx

It seems that TAGS have long been invented as well as methods for working with them - it is better to use them.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question