php - Laravel pagination with distinct
Get the solution ↓↓↓Solution:
Instead of using a distinct in this fashion, why not have the log actions stored uniquely in a relational table using methods firstOrCreate / firstOrNew on storing the actual log. You then would be able to use a proper eloquent model to paginate log actions table that would already be a unique list and use the ID of selection action to get all related logs.
table.logs id,action_id,users_id,...
table.logs_actions id,action_name
This would be less costly than a select distinct especially on a huge table.
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: sqlstate[23000]: integrity constraint violation: 1452 cannot add or update a child row: a foreign key constraint fails
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.