mirror of
https://github.com/snipe/snipe-it.git
synced 2024-12-25 05:34:06 -08:00
Dept search in User query scopes
This commit is contained in:
parent
e0d2cbef20
commit
aeca549bab
|
@ -24,7 +24,7 @@ class User extends SnipeModel implements AuthenticatableContract, CanResetPasswo
|
||||||
protected $hidden = ['password'];
|
protected $hidden = ['password'];
|
||||||
protected $table = 'users';
|
protected $table = 'users';
|
||||||
protected $injectUniqueIdentifier = true;
|
protected $injectUniqueIdentifier = true;
|
||||||
protected $fillable = ['first_name', 'last_name', 'email','password','username'];
|
protected $fillable = ['first_name', 'last_name', 'email','password','username','department_id'];
|
||||||
|
|
||||||
protected $casts = [
|
protected $casts = [
|
||||||
'activated' => 'boolean',
|
'activated' => 'boolean',
|
||||||
|
@ -106,6 +106,11 @@ class User extends SnipeModel implements AuthenticatableContract, CanResetPasswo
|
||||||
return $this->belongsTo('\App\Models\Company', 'company_id');
|
return $this->belongsTo('\App\Models\Company', 'company_id');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function department()
|
||||||
|
{
|
||||||
|
return $this->belongsTo('\App\Models\Department', 'department_id');
|
||||||
|
}
|
||||||
|
|
||||||
public function isActivated()
|
public function isActivated()
|
||||||
{
|
{
|
||||||
return $this->activated ==1;
|
return $this->activated ==1;
|
||||||
|
@ -358,6 +363,11 @@ class User extends SnipeModel implements AuthenticatableContract, CanResetPasswo
|
||||||
$query->where('locations.name', 'LIKE', '%'.$search.'%');
|
$query->where('locations.name', 'LIKE', '%'.$search.'%');
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
->orWhere(function ($query) use ($search) {
|
||||||
|
$query->whereHas('department', function ($query) use ($search) {
|
||||||
|
$query->where('departments.name', 'LIKE', '%'.$search.'%');
|
||||||
|
});
|
||||||
|
})
|
||||||
->orWhere(function ($query) use ($search) {
|
->orWhere(function ($query) use ($search) {
|
||||||
$query->whereHas('groups', function ($query) use ($search) {
|
$query->whereHas('groups', function ($query) use ($search) {
|
||||||
$query->where('groups.name', 'LIKE', '%'.$search.'%');
|
$query->where('groups.name', 'LIKE', '%'.$search.'%');
|
||||||
|
@ -413,4 +423,18 @@ class User extends SnipeModel implements AuthenticatableContract, CanResetPasswo
|
||||||
{
|
{
|
||||||
return $query->leftJoin('locations', 'users.location_id', '=', 'locations.id')->orderBy('locations.name', $order);
|
return $query->leftJoin('locations', 'users.location_id', '=', 'locations.id')->orderBy('locations.name', $order);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Query builder scope to order on department
|
||||||
|
*
|
||||||
|
* @param Illuminate\Database\Query\Builder $query Query builder instance
|
||||||
|
* @param text $order Order
|
||||||
|
*
|
||||||
|
* @return Illuminate\Database\Query\Builder Modified query builder
|
||||||
|
*/
|
||||||
|
public function scopeOrderDepartment($query, $order)
|
||||||
|
{
|
||||||
|
return $query->leftJoin('departments', 'users.department_id', '=', 'departments.id')->orderBy('departments.name', $order);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue