Nov 5, 2017
0
Level 1
Scout not paginating after defining custom toSearchableArray
I have a Post and a Category model. Each post can have many categories.
I'm trying to set my search so the keyword will be searched on posts and on its categories.
I achieved this by writing a custom toSearchableArray method on my Post model, but now my pagination is gone.
Here's the method
public function toSearchableArray()
{
$array = $this->toArray();
$array['categories'] = $this->categories;
return $array;
}
And here's how I'm calling it on the Controller
return Post::search($request->search)->paginate(2)->load('categories');
Any ideas on how I could solve this?
Please or to participate in this conversation.