Files
sam-manage/app/Models/Barobill/Client.php

34 lines
912 B
PHP
Raw Normal View History

<?php
namespace App\Models\Barobill;
use Illuminate\Database\Eloquent\Model;
/**
* 거래처 모델 (검색용)
* clients 테이블은 API 프로젝트에서 관리하며, MNG에서는 검색 조회만 수행
*/
class Client extends Model
{
protected $table = 'clients';
/**
* 고유번호(id) 또는 거래처명으로 검색
*/
public static function searchByIdOrName(int $tenantId, string $keyword, int $limit = 20)
{
return self::where('tenant_id', $tenantId)
->where('is_active', true)
->where(function ($query) use ($keyword) {
if (is_numeric($keyword)) {
$query->where('id', $keyword);
}
$query->orWhere('name', 'like', "%{$keyword}%");
})
->select('id', 'name')
->orderBy('id')
->limit($limit)
->get();
}
}