So I have two buttons, one is next and the other is prev. My objective is to increment the value everytime the button is clicked.. I guess after this I should just sell groceries or something, maybe I need some sleep, idk!...
Anyway, I would love to know how to do this..
Blade file
href="/?date=next"
href="/?date=prev"
Controller file
public function show(Hour $post){
if(request()->has('date')){
if(request('date') == 'next'){
$this->count++;
dd($this->count); // This value is not incrementing
}
}
}
Classes only live as long as the current request cycle. It does not matter if you stored a value in the class, next time you press the button you are in a completely new request cycle and with a new copy of the class again.
If for some reason you cannot use the frameworks paginator then you will need something like a page counter that is included in every request and incremented or decremented by the view.
So first page then your URL looks like /mypage?page=1 and you have a next button which has the url /mypage?page=2 then on page 2, a prev button which has /mypage?page=1 and a next button = /mypage?page=3
This is what the pagination class will do for you automatically.
@Snapey, thank you. But I do not want to use paginate in this scenario. There must be a way I can increment the value each time the user clicks the button.
What I am essentially trying to achieve is to show the user the rows for the next month.
And when that query parameter href=/?date=next, I run this method $post->date->nextMonth().
However, when the function is triggered, it does not update to the next month. Therefore I thought I just might add a value that increments to achieve this, like $post->date->nextMonth($count).
public function show(Hour $post){
if(request()->has('date')){
if(request('date') == 'next'){
dd(request('count')); // This value is from javascript
}
}
}