osb/app/Traits/ServiceDomains.php
Deon George 54cc99eac3
All checks were successful
Create Docker Image / Build Docker Image (x86_64) (push) Successful in 34s
Create Docker Image / Final Docker Image Manifest (push) Successful in 10s
Fix search and psql like queries need to be ilike for case insensitivity
2024-07-06 22:56:51 +10:00

59 lines
1.0 KiB
PHP

<?php
/**
* Service Types that have a domain name attribute.
*/
namespace App\Traits;
use App\Models\TLD;
trait ServiceDomains
{
/* INTERFACES */
/**
* There is no detailed description for domain services
*
* @return string
*/
public function getServiceDescriptionAttribute(): string
{
return '';
}
/**
* The name of the domain with its TLD
*
* @return string
*/
public function getServiceNameAttribute(): string
{
return strtoupper(sprintf('%s.%s',$this->domain_name,$this->tld->name));
}
/* RELATIONS */
public function tld()
{
return $this->belongsTo(TLD::class);
}
/* SCOPES */
/**
* Search for a record
*
* @param $query
* @param string $term
* @return mixed
*/
public function scopeSearch($query,string $term)
{
// If we have a period in the name, we'll ignore everything after it.
$term = strstr($term,'.',TRUE) ?: $term;
// Build our where clause
return parent::scopeSearch($query,$term)
->orwhere('domain_name','ilike','%'.$term.'%');
}
}