Laravel next and prev pagination post
up vote
1
down vote
favorite
In post, when I read post I have two button next post, and prev post. I want do this buttons and redirect user to next post or prev post. How I can do this correctly?
I have url post: http://example.com/post/1
<div class="entry-navigation">
{{-- <div class="column text-left"><a class="btn btn-outline-secondary btn-sm" href="{{ route('postshow', $offer->id - 1) }}"><i class="icon-arrow-left"></i> Prev</a></div> --}}
<div class="column"><a class="btn btn-outline-secondary view-all" href="{{ route('offers') }}" data-toggle="tooltip" data-placement="top" title="All posts"><i class="icon-menu"></i></a></div>
{{-- <div class="column text-right"><a class="btn btn-outline-secondary btn-sm" href="{{ route('postshow', $offer->id + 1) }}">Next <i class="icon-arrow-right"></i></a></div> --}}
</div>
I think with route
id +/- 1 I can do. But how I can check if post not deleted, or if he exists?
I can use and paginate
:
$posts = Post::active()->where('id', '!=', $post->id)->paginate(1);
But I get other links with ?page=1
.. ?page=10
How I get full link to next or prev post ?
php laravel
add a comment |
up vote
1
down vote
favorite
In post, when I read post I have two button next post, and prev post. I want do this buttons and redirect user to next post or prev post. How I can do this correctly?
I have url post: http://example.com/post/1
<div class="entry-navigation">
{{-- <div class="column text-left"><a class="btn btn-outline-secondary btn-sm" href="{{ route('postshow', $offer->id - 1) }}"><i class="icon-arrow-left"></i> Prev</a></div> --}}
<div class="column"><a class="btn btn-outline-secondary view-all" href="{{ route('offers') }}" data-toggle="tooltip" data-placement="top" title="All posts"><i class="icon-menu"></i></a></div>
{{-- <div class="column text-right"><a class="btn btn-outline-secondary btn-sm" href="{{ route('postshow', $offer->id + 1) }}">Next <i class="icon-arrow-right"></i></a></div> --}}
</div>
I think with route
id +/- 1 I can do. But how I can check if post not deleted, or if he exists?
I can use and paginate
:
$posts = Post::active()->where('id', '!=', $post->id)->paginate(1);
But I get other links with ?page=1
.. ?page=10
How I get full link to next or prev post ?
php laravel
I think it's better to use pagination with limit 1 for fetching your resource, then you have access to next and prev link. I you don't want to use pagination, then you should have methods to get prev and next id from your model. otherwise you have to implement many logic on your view.
– train_fox
Nov 12 at 10:58
@train_fox see please updated question
– Dumitru
Nov 12 at 11:02
On paginate response what you need arenext_page_url
andprev_page_url
. Don't worry about absolute url cause laravel fills it by your .env config.
– train_fox
Nov 12 at 12:16
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
In post, when I read post I have two button next post, and prev post. I want do this buttons and redirect user to next post or prev post. How I can do this correctly?
I have url post: http://example.com/post/1
<div class="entry-navigation">
{{-- <div class="column text-left"><a class="btn btn-outline-secondary btn-sm" href="{{ route('postshow', $offer->id - 1) }}"><i class="icon-arrow-left"></i> Prev</a></div> --}}
<div class="column"><a class="btn btn-outline-secondary view-all" href="{{ route('offers') }}" data-toggle="tooltip" data-placement="top" title="All posts"><i class="icon-menu"></i></a></div>
{{-- <div class="column text-right"><a class="btn btn-outline-secondary btn-sm" href="{{ route('postshow', $offer->id + 1) }}">Next <i class="icon-arrow-right"></i></a></div> --}}
</div>
I think with route
id +/- 1 I can do. But how I can check if post not deleted, or if he exists?
I can use and paginate
:
$posts = Post::active()->where('id', '!=', $post->id)->paginate(1);
But I get other links with ?page=1
.. ?page=10
How I get full link to next or prev post ?
php laravel
In post, when I read post I have two button next post, and prev post. I want do this buttons and redirect user to next post or prev post. How I can do this correctly?
I have url post: http://example.com/post/1
<div class="entry-navigation">
{{-- <div class="column text-left"><a class="btn btn-outline-secondary btn-sm" href="{{ route('postshow', $offer->id - 1) }}"><i class="icon-arrow-left"></i> Prev</a></div> --}}
<div class="column"><a class="btn btn-outline-secondary view-all" href="{{ route('offers') }}" data-toggle="tooltip" data-placement="top" title="All posts"><i class="icon-menu"></i></a></div>
{{-- <div class="column text-right"><a class="btn btn-outline-secondary btn-sm" href="{{ route('postshow', $offer->id + 1) }}">Next <i class="icon-arrow-right"></i></a></div> --}}
</div>
I think with route
id +/- 1 I can do. But how I can check if post not deleted, or if he exists?
I can use and paginate
:
$posts = Post::active()->where('id', '!=', $post->id)->paginate(1);
But I get other links with ?page=1
.. ?page=10
How I get full link to next or prev post ?
php laravel
php laravel
edited Nov 12 at 11:02
asked Nov 12 at 10:54
Dumitru
276112
276112
I think it's better to use pagination with limit 1 for fetching your resource, then you have access to next and prev link. I you don't want to use pagination, then you should have methods to get prev and next id from your model. otherwise you have to implement many logic on your view.
– train_fox
Nov 12 at 10:58
@train_fox see please updated question
– Dumitru
Nov 12 at 11:02
On paginate response what you need arenext_page_url
andprev_page_url
. Don't worry about absolute url cause laravel fills it by your .env config.
– train_fox
Nov 12 at 12:16
add a comment |
I think it's better to use pagination with limit 1 for fetching your resource, then you have access to next and prev link. I you don't want to use pagination, then you should have methods to get prev and next id from your model. otherwise you have to implement many logic on your view.
– train_fox
Nov 12 at 10:58
@train_fox see please updated question
– Dumitru
Nov 12 at 11:02
On paginate response what you need arenext_page_url
andprev_page_url
. Don't worry about absolute url cause laravel fills it by your .env config.
– train_fox
Nov 12 at 12:16
I think it's better to use pagination with limit 1 for fetching your resource, then you have access to next and prev link. I you don't want to use pagination, then you should have methods to get prev and next id from your model. otherwise you have to implement many logic on your view.
– train_fox
Nov 12 at 10:58
I think it's better to use pagination with limit 1 for fetching your resource, then you have access to next and prev link. I you don't want to use pagination, then you should have methods to get prev and next id from your model. otherwise you have to implement many logic on your view.
– train_fox
Nov 12 at 10:58
@train_fox see please updated question
– Dumitru
Nov 12 at 11:02
@train_fox see please updated question
– Dumitru
Nov 12 at 11:02
On paginate response what you need are
next_page_url
and prev_page_url
. Don't worry about absolute url cause laravel fills it by your .env config.– train_fox
Nov 12 at 12:16
On paginate response what you need are
next_page_url
and prev_page_url
. Don't worry about absolute url cause laravel fills it by your .env config.– train_fox
Nov 12 at 12:16
add a comment |
1 Answer
1
active
oldest
votes
up vote
-1
down vote
I'm posting a answer because i i dont have enough reputation.
Here is a link that can help you : Laravel previous and next records
I think its a duplicated question
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
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%2f53260629%2flaravel-next-and-prev-pagination-post%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
-1
down vote
I'm posting a answer because i i dont have enough reputation.
Here is a link that can help you : Laravel previous and next records
I think its a duplicated question
add a comment |
up vote
-1
down vote
I'm posting a answer because i i dont have enough reputation.
Here is a link that can help you : Laravel previous and next records
I think its a duplicated question
add a comment |
up vote
-1
down vote
up vote
-1
down vote
I'm posting a answer because i i dont have enough reputation.
Here is a link that can help you : Laravel previous and next records
I think its a duplicated question
I'm posting a answer because i i dont have enough reputation.
Here is a link that can help you : Laravel previous and next records
I think its a duplicated question
answered Nov 12 at 12:23
Alberto Guilherme
145
145
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%2f53260629%2flaravel-next-and-prev-pagination-post%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
I think it's better to use pagination with limit 1 for fetching your resource, then you have access to next and prev link. I you don't want to use pagination, then you should have methods to get prev and next id from your model. otherwise you have to implement many logic on your view.
– train_fox
Nov 12 at 10:58
@train_fox see please updated question
– Dumitru
Nov 12 at 11:02
On paginate response what you need are
next_page_url
andprev_page_url
. Don't worry about absolute url cause laravel fills it by your .env config.– train_fox
Nov 12 at 12:16