I am currently working on a project with multiple domains and languages ββwhere videos are reused with different names and descriptions.
My tables related to this relationship issue look like
posts >- videos >- videos_tags -< tags id id id id domain_id video_id video_id tag_id
Of course, I created models: Post, Video and Tag with all the necessary relationships.
What I'm trying to do is get all the posts on my tag model and maintain the pagination () functionality.
I can get all the tags associated with the message through the video module. However, when I try to make the return trip, I do not seem to retain the functionality of pagination (). I tried a lot, but I can not find the right solution.
The closest (I think) I was with this piece of code:
// App\Models\Tag public function posts() { $posts = []; foreach ($this->videos as $video) { foreach ($video->posts as $post) { if (!array_key_exists($post->id, $posts)) $posts[$post->id] = $post; } } return \Illuminate\Database\Eloquent\Collection::make($posts); }
Any suggestions or articles that I skipped while searching for an answer are welcome :)
php eloquent laravel
Thomas Van der Veen
source share