Some checks failed
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 3m24s
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 3m26s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 3m41s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 3m46s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 5m31s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 5m32s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 4m16s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 4m18s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m14s
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
28 lines
989 B
PHP
28 lines
989 B
PHP
<?php
|
|
|
|
namespace Inhaus\Plugins\News;
|
|
|
|
use App\Models\User;
|
|
use App\Search\GlobalSearch;
|
|
use Inhaus\Plugins\News\Models\NewsPost;
|
|
|
|
/** Suchquelle für die globale Suche */
|
|
class NewsSearch
|
|
{
|
|
/**
|
|
* @return list<array<string, mixed>>
|
|
*/
|
|
public function __invoke(User $user, string $search, int $limit): array
|
|
{
|
|
$query = NewsPost::query()->published()->visibleTo($user)->with('category');
|
|
GlobalSearch::whereTerms($query, ['title', 'teaser', 'body'], $search);
|
|
|
|
return $query->latest('published_at')->limit($limit)->get()->map(fn (NewsPost $post) => [
|
|
'title' => $post->title,
|
|
'url' => route('news.show', $post->slug),
|
|
'excerpt' => GlobalSearch::excerpt($post->teaser.' '.$post->body_html, $search),
|
|
'meta' => collect([$post->category?->name, $post->published_at?->translatedFormat('j. F Y')])->filter()->implode(' · '),
|
|
'image' => $post->coverUrl('thumb'),
|
|
])->all();
|
|
}
|
|
}
|