Answer the question
In order to leave comments, you need to log in
How to correctly move a function to a model in Laravel?
I have the following function call in the controller to get the latest topics.
Topic::join('blogs', 'topics.blog_id', '=', 'blogs.id')
->join('blog_subscriptions as us', function ($j) use ($userId) {
$j->on('us.blog_id', '=', 'blogs.id')
->where('us.user_id', '=', $userId);
})->get(['topics.*']);
Topic::getSubscribedTopics($userId);
Answer the question
In order to leave comments, you need to log in
Implement via the "Repository" pattern and store similar constructs in the repository without cluttering the model and controller. This is business logic and it would be nice to separate it from the application.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question