Clean up Transformers and extract an isDeletable() method to models where it makes sense.
This commit is contained in:
+10
-1
@@ -7,10 +7,11 @@ use App\Models\SnipeModel;
|
||||
use App\Models\Traits\Searchable;
|
||||
use App\Models\User;
|
||||
use App\Presenters\Presentable;
|
||||
use DB;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
use Watson\Validating\ValidatingTrait;
|
||||
use DB;
|
||||
|
||||
class Location extends SnipeModel
|
||||
{
|
||||
@@ -86,6 +87,14 @@ class Location extends SnipeModel
|
||||
'parent' => ['name']
|
||||
];
|
||||
|
||||
public function isDeletable()
|
||||
{
|
||||
return Gate::allows('delete', $this)
|
||||
&& ($this->assignedAssets()->count()===0)
|
||||
&& ($this->assets()->count()===0)
|
||||
&& ($this->users()->count()===0);
|
||||
}
|
||||
|
||||
public function users()
|
||||
{
|
||||
return $this->hasMany('\App\Models\User', 'location_id');
|
||||
|
||||
Reference in New Issue
Block a user