diff options
author | Igor Scheller <igor.scheller@igorshp.de> | 2019-07-28 17:14:42 +0200 |
---|---|---|
committer | Igor Scheller <igor.scheller@igorshp.de> | 2019-07-29 00:58:06 +0200 |
commit | 219c54411bb765bebd7813ad3e49ab05acf0b150 (patch) | |
tree | 9cf1cea8fccac16030e308df63352c2237311c0e /src/Models/Auth/Permission.php | |
parent | c1f6374f377d7b6d2aeefa464837226279a521a3 (diff) |
Permissions: Added models and migrations
Diffstat (limited to 'src/Models/Auth/Permission.php')
-rw-r--r-- | src/Models/Auth/Permission.php | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/src/Models/Auth/Permission.php b/src/Models/Auth/Permission.php new file mode 100644 index 00000000..1a4fd3e4 --- /dev/null +++ b/src/Models/Auth/Permission.php @@ -0,0 +1,57 @@ +<?php + +namespace Engelsystem\Models\Auth; + +use Engelsystem\Models\BaseModel; +use Illuminate\Database\Eloquent\Relations\BelongsToMany; +use Staudenmeir\EloquentHasManyDeep\HasManyDeep; + +/** + * @property integer $id + * @property string $name + * @property string|null $description + * @property \Carbon\Carbon $created_at + * @property \Carbon\Carbon $updated_at + * + * @property-read \Illuminate\Database\Query\Builder|\Engelsystem\Models\Auth\Role[] $roles + * @property-read \Illuminate\Database\Query\Builder|\Engelsystem\Models\User\User[] $users + * + * @method static \Illuminate\Database\Query\Builder|\Engelsystem\Models\User\User whereId($value) + * @method static \Illuminate\Database\Query\Builder|\Engelsystem\Models\User\User[] whereName($value) + * @method static \Illuminate\Database\Query\Builder|\Engelsystem\Models\User\User[] whereDescription($value) + * @method static \Illuminate\Database\Query\Builder|\Engelsystem\Models\User\User[] whereCreatedAt($value) + * @method static \Illuminate\Database\Query\Builder|\Engelsystem\Models\User\User[] whereUpdatedAt($value) + */ +class Permission extends BaseModel +{ + /** @var bool enable timestamps */ + public $timestamps = true; + + /** The attributes that are mass assignable */ + protected $fillable = [ + 'name', + 'description', + ]; + + /** + * The roles that have this permission + * + * @return BelongsToMany + */ + public function roles() + { + return $this + ->belongsToMany(Role::class) + ->withTimestamps(); + } + + /** + * The users that that have the permission + * + * @return HasManyDeep + */ + public function users() + { + return $this->hasManyDeepFromRelations($this->roles(), (new Role)->users()); + } +} |