BadMethodCallException Method Illuminate\Database\Eloquent\Collection::getCollection does not exist.
I want to return faqs with translation using pagination
when I try this code that error appear
what is the solution to do this ??
public function getFaqs()
{
if (config('app.locale') === 'en') {
$data = Faq::with('translations')
->get(['id', 'question', 'answer'])
->getCollection()
->transform(function($faq, $key) {
return [
'id' => $faq->id,
'question' => $faq->translate('en')->question,
'answer' => $faq->translate('en')->answer,
];
});
$data->paginate(10);
return $this->respondWithSuccess($data);
} else {
$data = Faq::select('id', 'question', 'answer')->paginate(10);
return $this->respondWithSuccess($data);
}
}
Method get already returns Collection.
$data = Faq::with('translations')
->get(['id', 'question', 'answer'])
->transform(function($faq, $key) {
return [
'id' => $faq->id,
'question' => $faq->translate('en')->question,
'answer' => $faq->translate('en')->answer,
];
});
@Yorki , I want to use pagination with collection,how can I do this
$data = Faq::with('translations')
->get(['id', 'question', 'answer'])
->transform(function($faq, $key) {
return [
'id' => $faq->id,
'question' => $faq->translate('en')->question,
'answer' => $faq->translate('en')->answer,
];
})->paginate(10);
BadMethodCallException
Method Illuminate\Database\Eloquent\Collection::paginate does not exist.
$data = Faq::with('translations')
->select(['id', 'question', 'answer'])
->paginate(20)
->transform(function($faq, $key) {
return [
'id' => $faq->id,
'question' => $faq->translate('en')->question,
'answer' => $faq->translate('en')->answer,
];
});
how can I return this keys
"first_page_url": "http://localhost/mertaah/api/ar/faqs?page=1",
"from": 1,
"last_page": 1,
"last_page_url": "http://localhost/mertaah/api/ar/faqs?page=1",
"next_page_url": null,
"path": "http://localhost/mertaah/api/ar/faqs",
"per_page": 10,
"prev_page_url": null,
"to": 3,
"total": 3
Please or to participate in this conversation.