Fix search and psql like queries need to be ilike for case insensitivity
This commit is contained in:
parent
61fe84498a
commit
54cc99eac3
@ -32,7 +32,7 @@ class BroadbandTraffic extends Command
|
||||
public function handle()
|
||||
{
|
||||
if ($this->option('supplier')) {
|
||||
$o = Supplier::where('name','like',$this->option('supplier'))->singleOrFail();
|
||||
$o = Supplier::where('name','ilike',$this->option('supplier'))->singleOrFail();
|
||||
|
||||
Job::dispatchSync($o->id);
|
||||
return;
|
||||
|
@ -7,7 +7,7 @@ use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
|
||||
use App\Models\{Account,Invoice,Payment,Service,Supplier,User};
|
||||
use App\Models\{Account,Invoice,Payment,Service,User};
|
||||
|
||||
class SearchController extends Controller
|
||||
{
|
||||
@ -29,12 +29,11 @@ class SearchController extends Controller
|
||||
if (! $request->input('term'))
|
||||
return $result;
|
||||
|
||||
$account_ids = ($x=Auth::user()->accounts)->pluck('id');
|
||||
$user_ids = $x->transform(function($item) { return $item->user;})->pluck('id');
|
||||
$account_ids = ($x=Auth::user()->accounts_all)->pluck('id');
|
||||
|
||||
# Look for User
|
||||
// Look for User
|
||||
foreach (User::Search($request->input('term'))
|
||||
->whereIN('id',$user_ids)
|
||||
->whereIN('id',$x->pluck('user_id')->unique())
|
||||
->orderBy('lastname')
|
||||
->orderBy('firstname')
|
||||
->limit(10)->get() as $o)
|
||||
@ -42,7 +41,7 @@ class SearchController extends Controller
|
||||
$result->push(['name'=>sprintf('%s (%s) - %s',$o->name,$o->lid,$o->email),'value'=>'/u/home/'.$o->id,'category'=>'Users']);
|
||||
}
|
||||
|
||||
# Look for User by Supplier
|
||||
// Look for User by their Supplier ID with some suppliers
|
||||
if (is_numeric($request->input('term')))
|
||||
foreach (User::select(['users.*','suppliers.name AS supplier_name','supplier_user.id AS pivot_id'])
|
||||
->join('supplier_user',['supplier_user.user_id'=>'users.id'])
|
||||
@ -56,16 +55,16 @@ class SearchController extends Controller
|
||||
$result->push(['name'=>sprintf('%s (%s:%s)',$o->name,$o->supplier_name,$o->pivot_id),'value'=>'/u/home/'.$o->id,'category'=>'Suppliers']);
|
||||
}
|
||||
|
||||
# Look for Account
|
||||
// Look for Account
|
||||
foreach (Account::Search($request->input('term'))
|
||||
->whereIN('user_id',$user_ids)
|
||||
->whereIN('id',$account_ids)
|
||||
->orderBy('company')
|
||||
->limit(10)->get() as $o)
|
||||
{
|
||||
$result->push(['name'=>sprintf('%s (%s)',$o->company,$o->lid),'value'=>'/u/home/'.$o->user_id,'category'=>'Accounts']);
|
||||
}
|
||||
|
||||
# Look for a Service
|
||||
// Look for a Service
|
||||
foreach (Service::Search($request->input('term'))
|
||||
->whereIN('account_id',$account_ids)
|
||||
->orderBy('id')
|
||||
@ -74,7 +73,7 @@ class SearchController extends Controller
|
||||
$result->push(['name'=>sprintf('%s (%s) %s',$o->name,$o->lid,$o->active ? '' : '<small>INACT</small>'),'value'=>'/u/service/'.$o->id,'category'=>$o->category_name]);
|
||||
}
|
||||
|
||||
# Look for an Invoice
|
||||
// Look for an Invoice
|
||||
foreach (Invoice::Search($request->input('term'))
|
||||
->whereIN('account_id',$account_ids)
|
||||
->orderBy('id')
|
||||
@ -84,7 +83,7 @@ class SearchController extends Controller
|
||||
}
|
||||
|
||||
if (Gate::any(['wholesaler'],new Payment)) {
|
||||
# Look for Payments
|
||||
// Look for Payments
|
||||
foreach (Payment::Search($request->input('term'))
|
||||
->whereIN('account_id',$account_ids)
|
||||
->limit(10)->get() as $o)
|
||||
|
@ -180,10 +180,10 @@ class Account extends Model implements IDs
|
||||
$query->where('id','like','%'.$term.'%');
|
||||
|
||||
} else {
|
||||
$query->where('company','like','%'.$term.'%')
|
||||
->orWhere('address1','like','%'.$term.'%')
|
||||
->orWhere('address2','like','%'.$term.'%')
|
||||
->orWhere('city','like','%'.$term.'%');
|
||||
$query->where('company','ilike','%'.$term.'%')
|
||||
->orWhere('address1','ilike','%'.$term.'%')
|
||||
->orWhere('address2','ilike','%'.$term.'%')
|
||||
->orWhere('city','ilike','%'.$term.'%');
|
||||
}
|
||||
|
||||
return $query;
|
||||
|
@ -530,18 +530,18 @@ class Service extends Model implements IDs
|
||||
return $query->select('services.*')
|
||||
->where('services.id','like',$t)
|
||||
->leftJoin('service_broadband',['service_broadband.service_id'=>'services.id'])
|
||||
->orWhere('service_broadband.service_number','like',$t)
|
||||
->orWhere('service_broadband.service_address','like',$t)
|
||||
->orWhere('service_broadband.ipaddress','like',$t)
|
||||
->orWhere('service_broadband.service_number','ilike',$t)
|
||||
->orWhere('service_broadband.service_address','ilike',$t)
|
||||
->orWhere('service_broadband.ipaddress','ilike',$t)
|
||||
->leftJoin('service_phone',['service_phone.service_id'=>'services.id'])
|
||||
->orWhere('service_phone.service_number','like',$t)
|
||||
->orWhere('service_phone.service_address','like',$t)
|
||||
->orWhere('service_phone.service_number','ilike',$t)
|
||||
->orWhere('service_phone.service_address','ilike',$t)
|
||||
->leftJoin('service_domain',['service_domain.service_id'=>'services.id'])
|
||||
->orWhere('service_domain.domain_name','like',$t)
|
||||
->orWhere('service_domain.domain_name','ilike',$t)
|
||||
->leftJoin('service_email',['service_email.service_id'=>'services.id'])
|
||||
->orWhere('service_email.domain_name','like',$t)
|
||||
->orWhere('service_email.domain_name','ilike',$t)
|
||||
->leftJoin('service_host',['service_host.service_id'=>'services.id'])
|
||||
->orWhere('service_host.domain_name','like',$t);
|
||||
->orWhere('service_host.domain_name','ilike',$t);
|
||||
}
|
||||
|
||||
/* ATTRIBUTES */
|
||||
|
@ -189,27 +189,27 @@ class User extends Authenticatable implements IDs
|
||||
{
|
||||
// Build our where clause
|
||||
// First Name, Last name
|
||||
if (preg_match('/\ /',$term)) {
|
||||
if (preg_match('/\s+/',$term)) {
|
||||
[$fn,$ln] = explode(' ',$term,2);
|
||||
|
||||
$query->where(function($query1) use ($fn,$ln,$term) {
|
||||
$query1->where(function($query2) use ($fn,$ln) {
|
||||
return $query2
|
||||
->where('firstname','like','%'.$fn.'%')
|
||||
->where('lastname','like','%'.$ln.'%');
|
||||
->where('firstname','ilike','%'.$fn.'%')
|
||||
->where('lastname','ilike','%'.$ln.'%');
|
||||
});
|
||||
});
|
||||
|
||||
} elseif (is_numeric($term)) {
|
||||
$query->where('users.id','like','%'.$term.'%');
|
||||
|
||||
} elseif (preg_match('/\@/',$term)) {
|
||||
$query->where('email','like','%'.$term.'%');
|
||||
} elseif (preg_match('/@/',$term)) {
|
||||
$query->where('email','ilike','%'.$term.'%');
|
||||
|
||||
} else {
|
||||
$query
|
||||
->Where('firstname','like','%'.$term.'%')
|
||||
->orWhere('lastname','like','%'.$term.'%');
|
||||
->Where('firstname','ilike','%'.$term.'%')
|
||||
->orWhere('lastname','ilike','%'.$term.'%');
|
||||
}
|
||||
|
||||
return $query;
|
||||
|
@ -54,6 +54,6 @@ trait ServiceDomains
|
||||
|
||||
// Build our where clause
|
||||
return parent::scopeSearch($query,$term)
|
||||
->orwhere('domain_name','like','%'.$term.'%');
|
||||
->orwhere('domain_name','ilike','%'.$term.'%');
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user