From f0123c6ba01c5034de030eb11fe72de855a5403e Mon Sep 17 00:00:00 2001 From: Jeremy Layson Date: Mon, 8 Apr 2024 21:36:27 +0800 Subject: [PATCH 1/3] Fix issue with search --- src/Filament/Blocks/RelatedResourceBlock.php | 9 +++++++-- src/Filament/Traits/HasExcerpt.php | 10 +++++++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/Filament/Blocks/RelatedResourceBlock.php b/src/Filament/Blocks/RelatedResourceBlock.php index db93c235..10cd1222 100644 --- a/src/Filament/Blocks/RelatedResourceBlock.php +++ b/src/Filament/Blocks/RelatedResourceBlock.php @@ -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) { diff --git a/src/Filament/Traits/HasExcerpt.php b/src/Filament/Traits/HasExcerpt.php index 188c52f6..d8001951 100644 --- a/src/Filament/Traits/HasExcerpt.php +++ b/src/Filament/Traits/HasExcerpt.php @@ -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; + } + } + } } } From 439ead90c730f1436023eb2ffe8f000022a2d5a0 Mon Sep 17 00:00:00 2001 From: Jeremy Layson Date: Mon, 8 Apr 2024 21:38:01 +0800 Subject: [PATCH 2/3] Fix Lint --- src/Filament/Blocks/RelatedResourceBlock.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Filament/Blocks/RelatedResourceBlock.php b/src/Filament/Blocks/RelatedResourceBlock.php index 10cd1222..db27e03a 100644 --- a/src/Filament/Blocks/RelatedResourceBlock.php +++ b/src/Filament/Blocks/RelatedResourceBlock.php @@ -85,10 +85,10 @@ public function getContents(string $search, $get): array $models = ($this->getSourceModel($source)) ->select('id', 'title') ->whereNotIn('id', $this->getExcludeIds($get)) - ->where(function($q) use ($search) { + ->where(function ($q) use ($search) { $q->where('contents', 'LIKE', '%' . $search . '%') ->orWhere('title', 'LIKE', '%' . $search . '%'); - + }) ->get(); From fa324f980e129e53dc354cf9d947c2c537a1761b Mon Sep 17 00:00:00 2001 From: Jeremy Layson Date: Tue, 9 Apr 2024 08:37:49 +0800 Subject: [PATCH 3/3] Adjusted HasExcerpt --- src/Filament/Traits/HasExcerpt.php | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/src/Filament/Traits/HasExcerpt.php b/src/Filament/Traits/HasExcerpt.php index d8001951..243cc0fb 100644 --- a/src/Filament/Traits/HasExcerpt.php +++ b/src/Filament/Traits/HasExcerpt.php @@ -12,23 +12,8 @@ trait HasExcerpt public function excerpt(): Attribute { $excerpt = $this->{$this->excerptField}; - $content = $excerpt['content']; - // get first content with "paragraph" - $paragraph = ''; - foreach ($content as $key => $value) { - if ($value['type'] === 'paragraph') { - 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; - } - } - } - } - } + $paragraph = tiptap_converter()->asText($excerpt) ?? ''; return Attribute::make(function () use ($paragraph) { return Str::take(Str::of($paragraph)->stripTags(), 200);