Added search on location parent for #1266

This commit is contained in:
snipe
2015-11-02 18:36:49 -08:00
parent 5bb94c4b4e
commit a9e1283a17
2 changed files with 19 additions and 14 deletions
+17 -13
View File
@@ -99,20 +99,24 @@ class Location extends Elegant
public function scopeTextsearch($query, $search)
{
return $query->where('name', 'LIKE', "%$search%")
->orWhere('address', 'LIKE', "%$search%")
->orWhere('city', 'LIKE', "%$search%")
->orWhere('state', 'LIKE', "%$search%")
->orWhere('zip', 'LIKE', "%$search%")
return $query->where('name', 'LIKE', "%$search%")
->orWhere('address', 'LIKE', "%$search%")
->orWhere('city', 'LIKE', "%$search%")
->orWhere('state', 'LIKE', "%$search%")
->orWhere('zip', 'LIKE', "%$search%")
// This doesn't actually work - need to use a table alias maybe?
->orWhere(function($query) use ($search) {
$query->whereHas('parent', function($query) use ($search) {
$query->where(function($query) use ($search) {
$query->where('name','LIKE','%'.$search.'%');
});
});
});
// This doesn't actually work - need to use a table alias maybe?
->orWhere(function($query) use ($search) {
$query->whereHas('parent', function($query) use ($search) {
$query->where(function($query) use ($search) {
$query->where('name','LIKE','%'.$search.'%');
});
})
// Ugly, ugly code because Laravel sucks at self-joins
->orWhere(function($query) use ($search) {
$query->whereRaw("parent_id IN (select id from locations where name LIKE '%".$search."%') ");
});
});
}
+2 -1
View File
@@ -30,7 +30,8 @@ Locations ::
<th data-sortable="true" data-field="id" data-visible="false">@lang('general.id')</th>
<th data-sortable="true" data-field="name">@lang('admin/locations/table.name')</th>
<th data-sortable="false" data-field="parent">@lang('admin/locations/table.parent')</th>
<th data-searchable="false" data-sortable="false" data-field="assets">@lang('general.assets')</th>
<th data-searchable="false" data-sortable="false" data-field="assets_default">@lang('admin/locations/table.assets_rtd')</th>
<th data-searchable="false" data-sortable="false" data-field="assets_checkedout">@lang('admin/locations/table.assets_checkedout')</th>
<th data-searchable="true" data-sortable="true" data-field="currency">@lang('general.currency')</th>
<th data-searchable="true" data-sortable="true" data-field="address">@lang('admin/locations/table.address')</th>
<th data-searchable="true" data-sortable="true" data-field="city">@lang('admin/locations/table.city')