mirror of
https://github.com/snipe/snipe-it.git
synced 2025-02-21 03:15:45 -08:00
Starter text search scope for activity report
(This will be messy)
This commit is contained in:
parent
e74a0171a6
commit
369715b7c7
|
@ -311,7 +311,7 @@ class ReportsController extends Controller
|
||||||
$activitylogs = Company::scopeCompanyables(Actionlog::with('item', 'user', 'target'))->orderBy('created_at', 'DESC');
|
$activitylogs = Company::scopeCompanyables(Actionlog::with('item', 'user', 'target'))->orderBy('created_at', 'DESC');
|
||||||
|
|
||||||
if (Input::has('search')) {
|
if (Input::has('search')) {
|
||||||
$activity = $activity->TextSearch(e(Input::get('search')));
|
$activitylogs = $activitylogs->TextSearch(e(Input::get('search')));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Input::has('offset')) {
|
if (Input::has('offset')) {
|
||||||
|
|
|
@ -45,6 +45,10 @@ class Actionlog extends Model
|
||||||
return $this->morphTo('item')->withTrashed();
|
return $this->morphTo('item')->withTrashed();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function company() {
|
||||||
|
return $this->hasMany('\App\Models\Company', 'id','company_id');
|
||||||
|
}
|
||||||
|
|
||||||
public function itemType()
|
public function itemType()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -129,4 +133,30 @@ class Actionlog extends Model
|
||||||
->orderBy('created_at', 'asc')
|
->orderBy('created_at', 'asc')
|
||||||
->get();
|
->get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Query builder scope to search on text for complex Bootstrap Tables API
|
||||||
|
*
|
||||||
|
* @param Illuminate\Database\Query\Builder $query Query builder instance
|
||||||
|
* @param text $search Search term
|
||||||
|
*
|
||||||
|
* @return Illuminate\Database\Query\Builder Modified query builder
|
||||||
|
*/
|
||||||
|
public function scopeTextSearch($query, $search)
|
||||||
|
{
|
||||||
|
$search = explode(' OR ', $search);
|
||||||
|
|
||||||
|
return $query->where(function ($query) use ($search) {
|
||||||
|
|
||||||
|
foreach ($search as $search) {
|
||||||
|
$query->where(function ($query) use ($search) {
|
||||||
|
$query->whereHas('company', function ($query) use ($search) {
|
||||||
|
$query->where('companies.name', 'LIKE', '%'.$search.'%');
|
||||||
|
});
|
||||||
|
})->orWhere('action_type', 'LIKE', '%'.$search.'%')
|
||||||
|
->orWhere('note', 'LIKE', '%'.$search.'%');
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue