I would like to ask laravel how to obtain the data of the b table associated with polymorphism through table an and filter it by page.

problem description

I now have a publish table that records the published data with the following fields:

clipboard.png

publish_articlepublish_activity:

clipboard.png

publish table has polymorphic association with other data tables . I need to get the specified amount of data from all the data published by a user, and perform Filter on the data, removing the data with is_drafts = 1 and visible = 0

.

what methods have you tried

1 I have tried to change the table and move the fields used for judgment (is_drafts,visible) to the publish table, but in addition, my praise table and favorite table also have the same structure and function as the publish table, and I don"t want to have these fields in every table, so I feel that the fields are redundant, so this method is abandoned by me.
2 I have also tried to fetch the paged data from the publish table and then go to Filter to get detailed data, but the data after Filter does not reach the amount required by paging. So I gave up, too.

at present, there are only these two methods that can be thought of. How can you achieve the effect of paging and Filter data in the case of polymorphic association?

Dec.21,2021

two schemes, inline, HasOne

< H2 > UserPublish.php < / H2 >

clipboard.png

clipboard.png

clipboard.png

clipboard.png


here is my table structure, user_publish is the record table, and the others are related data tables

$data = $this->model->whereHas('publish', function($query) {
    $query->where('is_drafts', 0);
})->get();
Menu