Files
mtdb_movie/app/Actions/LocalSearch.php
maher 703f50a09d
Some checks failed
Build / run (push) Has been cancelled
first commit
2025-10-29 11:42:25 +01:00

42 lines
1.0 KiB
PHP
Executable File

<?php
namespace App\Actions;
use App\Actions\People\LoadPrimaryCredit;
use App\Models\Person;
use App\Models\Title;
use Illuminate\Support\Arr;
use Illuminate\Support\Collection;
class LocalSearch
{
public function execute(string $query, array $params = []): Collection
{
$titles = collect();
$people = collect();
if (Arr::get($params, 'type') !== 'person') {
$titles = Title::search($query)
->take(20)
->get();
if ($with = Arr::get($params, 'with')) {
$with = array_filter(explode(',', $with));
$titles->load($with);
}
}
if (Arr::get($params, 'type') !== 'title') {
$people = Person::search($query)
->take(20)
->get();
app(LoadPrimaryCredit::class)->execute($people);
}
return $titles
->concat($people)
->slice(0, Arr::get($params, 'limit', 8))
->values();
}
}