Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue with search #30

Merged
merged 4 commits into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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') {
jeremy-portable marked this conversation as resolved.
Show resolved Hide resolved
$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
Loading