0

Using meilisearch scout, and want to get specific columns only on response. (To descrease the result size)

    $products = Product::search('blabla')
        ->select('title', 'id')
        ->paginate($paginate)
        ->load(['cover']);

But it returns error like that

Method Laravel\Scout\Builder::select does not exist

How can I pick specific columns?

1 Answers1

0

If you're trying to retrieve the data using ->paginate() method, you must need to load the relations separately. For example:

$products = Product::search('blabla')
        ->query(function($query) { 
            $query->addSelect(['title', 'id']);  
        })
        ->paginate($paginate);
$products->load(['cover']);
cengsemihsahin
  • 921
  • 2
  • 8
  • 21
  • may I ask you to take a look at a Laravel search related question here : https://stackoverflow.com/questions/76485513/laravel-search-with-multiple-keywords-against-multiple-columns-with-the-search ? – Istiaque Ahmed Jun 15 '23 at 22:20