Skip to content

Commit

Permalink
Fix issue with search
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremy-layson committed Apr 8, 2024
1 parent d27ab6a commit f0123c6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
9 changes: 7 additions & 2 deletions src/Filament/Blocks/RelatedResourceBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,14 @@ public function getContents(string $search, $get): array
$models = null;
$source = $get('source');

$models = ($this->getSourceModel($source))->select('id', 'title')
$models = ($this->getSourceModel($source))
->select('id', 'title')
->whereNotIn('id', $this->getExcludeIds($get))
->where('contents', 'LIKE', '%' . $search . '%')
->where(function($q) use ($search) {
$q->where('contents', 'LIKE', '%' . $search . '%')
->orWhere('title', 'LIKE', '%' . $search . '%');

})
->get();

foreach ($models as $key => $model) {
Expand Down
10 changes: 9 additions & 1 deletion src/Filament/Traits/HasExcerpt.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,15 @@ public function excerpt(): Attribute
$paragraph = '';
foreach ($content as $key => $value) {
if ($value['type'] === 'paragraph') {
$paragraph = $value['content'][0]['text']; // take the first part
if (isset($value['content'])) {
foreach ($value['content'] as $key => $valueContent) {
// find first instance of text
if (isset($valueContent['text'])) {
$paragraph = $valueContent['text']; // take the first part
break;
}
}
}
}
}

Expand Down

0 comments on commit f0123c6

Please sign in to comment.