Rename ab_account to accounts

This commit is contained in:
Deon George
2021-07-07 17:45:16 +10:00
parent f6751e7a63
commit 24ff62094a
5 changed files with 41 additions and 106 deletions

View File

@@ -26,8 +26,8 @@ class Account extends Model implements IDs
const RECORD_ID = 'account';
public $incrementing = FALSE;
protected $table = 'ab_account';
public $timestamps = FALSE;
const CREATED_AT = 'date_orig';
const UPDATED_AT = 'date_last';
protected $appends = [
'active_display',
@@ -97,30 +97,14 @@ class Account extends Model implements IDs
public function scopeSearch($query,string $term)
{
// Build our where clause
// First Name, Last name
if (preg_match('/\ /',$term)) {
[$fn,$ln] = explode(' ',$term,2);
$query->where(function($query1) use ($fn,$ln,$term) {
$query1->where(function($query2) use ($fn,$ln) {
return $query2
->where('first_name','like','%'.$fn.'%')
->where('last_name','like','%'.$ln.'%');
})
->orWhere('company','like','%'.$term.'%');
});
} elseif (is_numeric($term)) {
if (is_numeric($term)) {
$query->where('id','like','%'.$term.'%');
} elseif (preg_match('/\@/',$term)) {
$query->where('email','like','%'.$term.'%');
} else {
$query
->where('company','like','%'.$term.'%')
->orWhere('first_name','like','%'.$term.'%')
->orWhere('last_name','like','%'.$term.'%');
$query->where('company','like','%'.$term.'%')
->orWhere('address1','like','%'.$term.'%')
->orWhere('address2','like','%'.$term.'%')
->orWhere('city','like','%'.$term.'%');
}
return $query;