M
M
mrdragon90002019-02-26 11:35:43
Laravel
mrdragon9000, 2019-02-26 11:35:43

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

2 answer(s)
K
Konstantin B., 2019-02-26
@Kostik_1993

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

R
Roman, 2019-02-26
@procode

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 question

Ask a Question

731 491 924 answers to any question