21 lines
499 B
PHP
21 lines
499 B
PHP
<?php
|
|
|
|
namespace App\Services;
|
|
|
|
use App\Models\Guest;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
class GuestSearch
|
|
{
|
|
public function search(string $query)
|
|
{
|
|
return Guest::where('name', 'like', "%{$query}%")
|
|
->orWhere('phone', 'like', "%{$query}%")
|
|
->orWhere('email', 'like', "%{$query}%")
|
|
->orderByRaw("CASE WHEN phone LIKE '%{$query}%' THEN 1 ELSE 2 END")
|
|
->orderBy('updated_at', 'desc')
|
|
->limit(20)
|
|
->get();
|
|
}
|
|
}
|