Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

User activity #82

Closed
wants to merge 3 commits into from
Closed

User activity #82

wants to merge 3 commits into from

Conversation

grozwalker
Copy link
Contributor

No description provided.

$completeChapters = collect($request->get('chapters_id', []));
$userChapters = $user->chapters()->pluck('chapter_id');

$chaptersToCreate = $completeChapters->diff($userChapters);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Т.к. при сохранении прочитанных глав мы вначале удаляем все прочитанные главы, а потом просто записываем все прочитанные, то получается у нас бы дублировались записи в логе о прочитанности глав. Поэтому сохраняю только те, которые добавились

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

А зачем удалять прочитанные главы?



$user->chapters()->detach($chaptersToDelete);
foreach ($chaptersToCreate as $chapterId) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Событие модели не срабатывают на метод sync, чтобы они работали, надо сохранять по-одному. Поэтому здесь прохожусь в цикле и создаю запись о прочитанности

@fey fey closed this Dec 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants