Post is for saving data not retrieving data. Are you using ajax or regular forms?
pagination
im posting values to a controller function and getting results with paginate. pagination doesnt work with post request. how to resolve.
im using reqular forms.
@beracah.kings depends on how you build your pagination links, but, all you need to do is to send page parameter to the request
curl -d "page=1" -X POST http://localhost:8000/users
Why does the route need to be POST? A GET request would make more sense if you are simply getting paginated data based on some values.
@beracah.kings I advise you to follow @sinnbeck , because using GET is easier for who want to share you page link and other needed things
im collecting data from a form and then submitting to page, after some updates, the data is sent back. i m submitting 10 fields, so will that be odd to pass the parameters in get. can it be done through redirect
Yes but you will then need to set the page number yourself like @sergiu17 said (unless it should just be page 1)
thank you sinnbeck. if i pass values through querystring, only the first page display displays correctly, the second pagination link fetches all the data. What could be wrong.
Show some code then please. :)
$gender = $request->input('gender');
$mothertongue = $request->input('mothertongue');
$maritalstatus = $request->input('maritalstatus');
$caste = $request->input('caste');
$denomination = $request->input('denomination');
$partnerprofile2=new \App\partnerprofile;
$partnerprofile=$partnerprofile2
->when($gender, function($query, $gender) {
$query->where('gender', $gender);
})->when($mothertongue, function($query, $mothertongue) {
$query->where('mothertongue', $mothertongue);
})->when($maritalstatus, function($query, $maritalstatus) {
$query->where('maritalstatus', $maritalstatus);
})->when($caste, function($query, $caste) {
$query->where('caste', $caste);
})->when($denomination, function($query, $denomination) {
$query->where('denomination', $denomination);
})
->paginate(10);
return view('search.response')->with(['partnerprofile'=>$partnerprofile]);
Is that a post or get route? And are you sure page is set? Check $request->input('page');
@sinnbeck if the values are in the query string, then pagination doesnt work. Only if the values are set inside the controller action then pagination works.
You can just pass the page manually if it does not work
->paginate(10, ['*'], 'page',$request->page);
This answer worked for me
{{ $partnerprofile->appends(request()->except('page'))->links() }}
Im appending the querystring into the url . Now its working
Great. Remember to mark your answer as best
do we have to sanitize the input, im using eloquent for data retrieval
Yes always sanitize your inputs. Users are evil (well some are)
This is the most under explained feature of Laravel I have come across so far. There are mysterious variables ($paginator) that is used in the views/vendor/pagination/bootstrap-4.blade.php, ($elements) that throws an error , no explanation of what file these bits are supposed to be, what they represent, what file they are used inside of, no explaination of anything!
I have admittedly been trying to bite off more than I an chew by also including Vue components in the mix but that is another issue altogether.
I have the correct data coming back (FINALLY) from the api route where the pagination links and meta are correct and accounted for. My list of items is correctly displayed in a Vue component. If I add ANY extra piece to the mix in any file at ANY time, the navbar.vue stops functioning without explaination, the item list never fires and there is no console error or warnig. Just NOTHING. SO frustrating!
I know that some fellow egg head out there will say "show me the code else I can't understand". Well none of the code works! It is absent when the page works and nothing is there when I add it. I just need to know where therse variables are first mentioned, what they represent, what file they are defined in and what visibility they are supposed to have.
@alan9608 you can search through the API for greater detail: https://laravel.com/api/6.x/
Also for further questions, probably better to start a new post, since this one has been resolved.
Please or to participate in this conversation.