Visitor management app with SSO, kiosk, badges, reports, and Gitea CI deploy to frontdesk.ladill.com. Co-authored-by: Cursor <cursoragent@cursor.com>
32 lines
948 B
PHP
32 lines
948 B
PHP
<?php
|
|
|
|
namespace App\Services\Frontdesk;
|
|
|
|
use App\Models\Visitor;
|
|
use Illuminate\Database\Eloquent\Collection;
|
|
|
|
class VisitorSearchService
|
|
{
|
|
/** @return Collection<int, Visitor> */
|
|
public function search(string $ownerRef, int $organizationId, string $query, int $limit = 20): Collection
|
|
{
|
|
$query = trim($query);
|
|
if ($query === '') {
|
|
return new Collection;
|
|
}
|
|
|
|
return Visitor::owned($ownerRef)
|
|
->where('organization_id', $organizationId)
|
|
->where(function ($q) use ($query) {
|
|
$q->where('full_name', 'like', "%{$query}%")
|
|
->orWhere('company', 'like', "%{$query}%")
|
|
->orWhere('phone', 'like', "%{$query}%")
|
|
->orWhere('email', 'like', "%{$query}%");
|
|
})
|
|
->orderByDesc('is_frequent')
|
|
->orderBy('full_name')
|
|
->limit($limit)
|
|
->get();
|
|
}
|
|
}
|