3
0
mirror of https://github.com/snipe/snipe-it.git synced 2026-02-05 06:55:34 +00:00

Full kits manipulation without users intagration

This commit is contained in:
Minaev Dmitriy
2018-11-06 19:27:28 +03:00
parent 9d5cd27575
commit 79d979f47f
6 changed files with 76 additions and 26 deletions

View File

@ -8,6 +8,7 @@ use App\Presenters\Presentable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Watson\Validating\ValidatingTrait;
use Illuminate\Validation\Rule;
/**
* Model for Categories. Categories are a higher-level group
@ -34,10 +35,28 @@ class PredefinedKit extends SnipeModel
public $modelRules = [
'model_id' => 'required|exists:models,id',
// 'model_id' => [
// 'required',
// 'exists:models,id',
// Rule::unique('kits_models')->where('model_id', $model_id)->whereNot('kit_id', $this->id)
// ],
'quantity' => 'required|integer|min:1',
'pivot_id' => 'integer|exists:kits_models,id'
];
public function makeModelRules($model_id) {
return [
// 'model_id' => 'required|exists:models,id',
'model_id' => [
'required',
'exists:models,id',
Rule::unique('kits_models')->whereNot('model_id', $model_id)->where('kit_id', $this->id)
],
'quantity' => 'required|integer|min:1',
'pivot_id' => 'integer|exists:kits_models,id'
];
}
public $licenseRules = [
'license_id' => 'required|exists:licenses,id',
'quantity' => 'required|integer|min:1',
@ -83,6 +102,11 @@ class PredefinedKit extends SnipeModel
return $this->belongsToMany('\App\Models\AssetModel', 'kits_models', 'kit_id', 'model_id')->withPivot('id', 'quantity');
}
public function assets()
{
return $this->hasManyThrough('\App\Models\Asset', '\App\Models\AssetModel', 'country_id', 'user_id');
}
/**
* Establishes the kits -> licenses relationship
*
@ -96,6 +120,9 @@ class PredefinedKit extends SnipeModel
}
public function applyToUser(User $user) {
$models = $this->models();
}
/**
* -----------------------------------------------