Answer the question
In order to leave comments, you need to log in
Laravel, relation to check that the news has been read by the user?
There is a User model, there is a News model (news). How to store marks that the news has been read by the user, how to register a link and check it?
Answer the question
In order to leave comments, you need to log in
There is a news table, there is a users table
We need another user_news_reads for example
It has two columns user_id, news_id then
work through the belongsToMany connection
This is a many-to-many relationship. Better than in the documentation:
https://laravel.ru/docs/v5/eloquent-relationships#mm
perhaps you can’t describe :)
In general terms, I would do this: in the NewsController, when we show the news to the user, we set the relationship between him and the news , and then, where necessary, we check whether there is such an attitude (the news has been read) or not (the news has not been read).
If you have more specific questions, please ask.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question