0
    $data = Category::join('articles', function ($join) {
       $join->on('categories.id', 'articles.category_id')
        ->where('categories.type', 'news')
        ->where('articles.status', '1');
    })->get()->sortByDesc('updated_at')->paginate(5);

I have 2 variables both querying the same model. I want to now merge these 2 separate datasets into a variable called $articles and then paginate on it.

2 Answers2

0

Remove the get() method from the code like:

$data = Category::join('articles', function ($join) {
    $join->on('categories.id', 'articles.category_id')
    ->where('categories.type', 'news')
    ->where('articles.status', '1');
})->sortByDesc('updated_at')->paginate(5);

It should work.

engrhussainahmad
  • 1,008
  • 10
  • 19
0

When joining queries and paginate in controller, to view the output in paginate you should include this under you for loop output:

{{ $data->links() }}
joun
  • 656
  • 1
  • 8
  • 25