mirror of
https://github.com/snipe/snipe-it.git
synced 2025-03-05 20:52:15 -08:00
Allow location/company/manager to be null via validation
This commit is contained in:
parent
b223630f72
commit
96e8109d01
|
@ -1,6 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App;
|
namespace App\Models;
|
||||||
|
|
||||||
use App\Http\Traits\UniqueUndeletedTrait;
|
use App\Http\Traits\UniqueUndeletedTrait;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
@ -24,10 +24,10 @@ class Department extends SnipeModel
|
||||||
use ValidatingTrait, UniqueUndeletedTrait;
|
use ValidatingTrait, UniqueUndeletedTrait;
|
||||||
|
|
||||||
protected $rules = [
|
protected $rules = [
|
||||||
'name' => 'max:255',
|
'name' => 'required|max:255',
|
||||||
'user_id' => 'required',
|
'user_id' => 'required',
|
||||||
'location_id' => 'numeric',
|
'location_id' => 'numeric|nullable',
|
||||||
'company_id' => 'numeric',
|
'company_id' => 'numeric|nullable',
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -60,4 +60,37 @@ class Department extends SnipeModel
|
||||||
return $this->hasMany('\App\Models\User', 'department_id');
|
return $this->hasMany('\App\Models\User', 'department_id');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the manager in charge of the dept
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function manager()
|
||||||
|
{
|
||||||
|
return $this->belongsTo('\App\Models\User', 'manager_id');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function location()
|
||||||
|
{
|
||||||
|
return $this->belongsTo('\App\Models\Location', 'location_id');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Query builder scope to search on text
|
||||||
|
*
|
||||||
|
* @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)
|
||||||
|
{
|
||||||
|
return $query->where('name', 'LIKE', "%$search%")
|
||||||
|
->orWhere('notes', 'LIKE', "%$search%");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue