pagination not work
in controller
public function getFaqs()
{
if (config('app.locale') === 'en') {
$data = Faq::get();
foreach ($data as $value) {
return [
'id' => $value->id,
'question' => $value->translate('en')->question,
'answer' => $value->translate('en')->answer,
];
}
$data->paginate(2);
return $this->respondWithSuccess($data);
} else {
$data = Faq::select('id', 'question', 'answer')->paginate(10);
return $this->respondWithSuccess($data);
}
}
why pagination not work hear and it return the latest item only not all faq in database
foreach ($data as $value) {
return [
'id' => $value->id,
'question' => $value->translate('en')->question,
'answer' => $value->translate('en')->answer,
];
}
No matter how many items $data contains, this loop will loop only one time. because you return :)
https://www.w3schools.com/php/default.asp :)
Please or to participate in this conversation.