HELP getGlobalSearchResults

Why if i use getGlobalSearchResults i have no attributes
public static function getGlobalSearchResults(string $searchQuery): Collection
{
$risultato = Pfc::query()
->where('codice', 'like', "%{$searchQuery}%")
->orWhereHas('pfcArticoli',
function($internalQuery) use ($searchQuery){
$internalQuery->join('articoli', 'articoli.id', '=', 'pfc_articolo.articolo_id')
->where('descrizione', 'like', "%{$searchQuery}%");
})
->get();
return $risultato;
}
public static function getGlobalSearchResults(string $searchQuery): Collection
{
$risultato = Pfc::query()
->where('codice', 'like', "%{$searchQuery}%")
->orWhereHas('pfcArticoli',
function($internalQuery) use ($searchQuery){
$internalQuery->join('articoli', 'articoli.id', '=', 'pfc_articolo.articolo_id')
->where('descrizione', 'like', "%{$searchQuery}%");
})
->get();
return $risultato;
}
This is the results
No description
Solution:
Here's how I solved it ```php public static function getGlobalSearchResultDetails(Model $record): array { //dd($record);...
No description
Jump to solution
3 Replies
MohamedSabil83
MohamedSabil838mo ago
I guess you forget to prepare how to display the result. Take a look here https://filamentphp.com/docs/2.x/admin/resources/global-search
Marco Mapelli
Marco MapelliOP8mo ago
No, I've already gone through all the documentation, but the result remains the same, even when using getGloballySearchableAttributes, getGlobalSearchResultDetails. This
public static function getGlobalSearchResults(string $searchQuery): Collection
{
$risultato = Pfc::with('articoli')
->where('codice', 'like', "%{$searchQuery}%")
->orWhereHas('pfcArticoli',
function($internalQuery) use ($searchQuery){
$internalQuery->join('articoli', 'articoli.id', '=', 'pfc_articolo.articolo_id')
->where('descrizione', 'like', "%{$searchQuery}%");
})
->get()
->map(function (Model $record): ?GlobalSearchResult {
$url = static::getGlobalSearchResultUrl($record);

if (blank($url)) {
return null;
}

return new GlobalSearchResult(
title: static::getGlobalSearchResultTitle($record),
url: $url,
details: static::getGlobalSearchResultDetails($record),
actions: static::getGlobalSearchResultActions($record),
);
})
->filter();
// dd($risultato);
// dd(parent::getGlobalSearchResults($searchQuery));
return $risultato;
}
public static function getGlobalSearchResults(string $searchQuery): Collection
{
$risultato = Pfc::with('articoli')
->where('codice', 'like', "%{$searchQuery}%")
->orWhereHas('pfcArticoli',
function($internalQuery) use ($searchQuery){
$internalQuery->join('articoli', 'articoli.id', '=', 'pfc_articolo.articolo_id')
->where('descrizione', 'like', "%{$searchQuery}%");
})
->get()
->map(function (Model $record): ?GlobalSearchResult {
$url = static::getGlobalSearchResultUrl($record);

if (blank($url)) {
return null;
}

return new GlobalSearchResult(
title: static::getGlobalSearchResultTitle($record),
url: $url,
details: static::getGlobalSearchResultDetails($record),
actions: static::getGlobalSearchResultActions($record),
);
})
->filter();
// dd($risultato);
// dd(parent::getGlobalSearchResults($searchQuery));
return $risultato;
}
error App\Filament\Resources\PfcResource::getGlobalSearchResults(): Return value must be of type Illuminate\Database\Eloquent\Collection, Illuminate\Support\Collection returned
Solution
Marco Mapelli
Marco Mapelli8mo ago
Here's how I solved it
public static function getGlobalSearchResultDetails(Model $record): array
{
//dd($record);
return [
// 'Codice' => $record->codice,
'Descrizione' => $record->articoli->pluck('descrizione')->join(', '),
];
}
public static function getGlobalSearchResults(string $searchQuery): Collection
{
$risultato = Pfc::with('articoli')
->where('codice', 'like', "%{$searchQuery}%")
->orWhereHas('pfcArticoli',
function($internalQuery) use ($searchQuery){
$internalQuery->join('articoli', 'articoli.id', '=', 'pfc_articolo.articolo_id')
->where('descrizione', 'like', "%{$searchQuery}%");
})
->get()
->map(function (Model $record): ?GlobalSearchResult {
$url = static::getGlobalSearchResultUrl($record);

if (blank($url)) {
return null;
}

return new GlobalSearchResult(
title: static::getGlobalSearchResultTitle($record),
url: $url,
details: static::getGlobalSearchResultDetails($record),
actions: static::getGlobalSearchResultActions($record),
);
})
->filter();
return new \Illuminate\Database\Eloquent\Collection($risultato);
}
public static function getGlobalSearchResultDetails(Model $record): array
{
//dd($record);
return [
// 'Codice' => $record->codice,
'Descrizione' => $record->articoli->pluck('descrizione')->join(', '),
];
}
public static function getGlobalSearchResults(string $searchQuery): Collection
{
$risultato = Pfc::with('articoli')
->where('codice', 'like', "%{$searchQuery}%")
->orWhereHas('pfcArticoli',
function($internalQuery) use ($searchQuery){
$internalQuery->join('articoli', 'articoli.id', '=', 'pfc_articolo.articolo_id')
->where('descrizione', 'like', "%{$searchQuery}%");
})
->get()
->map(function (Model $record): ?GlobalSearchResult {
$url = static::getGlobalSearchResultUrl($record);

if (blank($url)) {
return null;
}

return new GlobalSearchResult(
title: static::getGlobalSearchResultTitle($record),
url: $url,
details: static::getGlobalSearchResultDetails($record),
actions: static::getGlobalSearchResultActions($record),
);
})
->filter();
return new \Illuminate\Database\Eloquent\Collection($risultato);
}
No description
Want results from more Discord servers?
Add your server