How do i join two queries and then paginate
up vote
0
down vote
favorite
$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.
laravel-5 eloquent laravel-paginate
add a comment |
up vote
0
down vote
favorite
$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.
laravel-5 eloquent laravel-paginate
Just remove get() and your query should work.
– Web Artisan
Nov 8 at 14:41
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
$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.
laravel-5 eloquent laravel-paginate
$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.
laravel-5 eloquent laravel-paginate
laravel-5 eloquent laravel-paginate
asked Nov 8 at 13:49
Prateep Aun-aok
31
31
Just remove get() and your query should work.
– Web Artisan
Nov 8 at 14:41
add a comment |
Just remove get() and your query should work.
– Web Artisan
Nov 8 at 14:41
Just remove get() and your query should work.
– Web Artisan
Nov 8 at 14:41
Just remove get() and your query should work.
– Web Artisan
Nov 8 at 14:41
add a comment |
2 Answers
2
active
oldest
votes
up vote
0
down vote
accepted
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.
Great, It work. thank you :)
– Prateep Aun-aok
Nov 10 at 10:42
add a comment |
up vote
0
down vote
When joining queries and paginate in controller, to view the output in paginate you should include this under you for loop output:
{{ $data->links() }}
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
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.
Great, It work. thank you :)
– Prateep Aun-aok
Nov 10 at 10:42
add a comment |
up vote
0
down vote
accepted
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.
Great, It work. thank you :)
– Prateep Aun-aok
Nov 10 at 10:42
add a comment |
up vote
0
down vote
accepted
up vote
0
down vote
accepted
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.
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.
answered Nov 8 at 15:09
engrhussainahmad
1257
1257
Great, It work. thank you :)
– Prateep Aun-aok
Nov 10 at 10:42
add a comment |
Great, It work. thank you :)
– Prateep Aun-aok
Nov 10 at 10:42
Great, It work. thank you :)
– Prateep Aun-aok
Nov 10 at 10:42
Great, It work. thank you :)
– Prateep Aun-aok
Nov 10 at 10:42
add a comment |
up vote
0
down vote
When joining queries and paginate in controller, to view the output in paginate you should include this under you for loop output:
{{ $data->links() }}
add a comment |
up vote
0
down vote
When joining queries and paginate in controller, to view the output in paginate you should include this under you for loop output:
{{ $data->links() }}
add a comment |
up vote
0
down vote
up vote
0
down vote
When joining queries and paginate in controller, to view the output in paginate you should include this under you for loop output:
{{ $data->links() }}
When joining queries and paginate in controller, to view the output in paginate you should include this under you for loop output:
{{ $data->links() }}
answered Nov 9 at 0:37
joun
47114
47114
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53209084%2fhow-do-i-join-two-queries-and-then-paginate%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Just remove get() and your query should work.
– Web Artisan
Nov 8 at 14:41