A free open source IT asset/license management system
Allow location/company/manager to be null via validation
snipe96e8109d0123
diff --git a/app/Models/Department.php b/app/Models/Department.phpindex 95c8e2702c..a97e147ee1 100644--- a/app/Models/Department.php+++ b/app/Models/Department.php@@ -1,6 +1,6 @@<?php-namespace App;+namespace App\Models;use App\Http\Traits\UniqueUndeletedTrait;use Illuminate\Database\Eloquent\Model;@@ -24,10 +24,10 @@ class Department extends SnipeModeluse ValidatingTrait, UniqueUndeletedTrait;protected $rules = [- 'name' => 'max:255',+ 'name' => 'required|max:255','user_id' => 'required',- 'location_id' => 'numeric',- 'company_id' => 'numeric',+ 'location_id' => 'numeric|nullable',+ 'company_id' => 'numeric|nullable',];/**@@ -60,4 +60,37 @@ class Department extends SnipeModelreturn $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%");++ }++}