laravel-scout-tntsearch-driver
laravel-scout-tntsearch-driver copied to clipboard
Return specific columns
Hello, i want to make this query:
$persons = Person::search($search_value)->get(['id', 'first_name]);
Can anyone tell me if this is possible?
Hi,
$persons = Person::search($search_value)->pluck('id','name);
?
return a collection, so add ->toArray() method at the end if you want an array :)
I've done this…
$companies = Company::search($searchString)->get();
$companyids = array();
foreach ($companies as $company) {
$companyids[] = $company->id;
}
I'm sure there is a better way but it works
For anyone still interested, you can pass a callback function to the Scout Builder instance.
$columns = ['id', 'name'];
Person::search($searchString)->query(function($query) use ($columns) {
$query->select($columns);
})->get();