From 219c54411bb765bebd7813ad3e49ab05acf0b150 Mon Sep 17 00:00:00 2001 From: Igor Scheller Date: Sun, 28 Jul 2019 17:14:42 +0200 Subject: Permissions: Added models and migrations --- src/Models/Auth/Permission.php | 57 +++++++++++++++++++++++++++++++++ src/Models/Auth/Role.php | 71 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 128 insertions(+) create mode 100644 src/Models/Auth/Permission.php create mode 100644 src/Models/Auth/Role.php (limited to 'src/Models/Auth') 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 @@ +belongsToMany(Role::class) + ->withTimestamps(); + } + + /** + * The users that that have the permission + * + * @return HasManyDeep + */ + public function users() + { + return $this->hasManyDeepFromRelations($this->roles(), (new Role)->users()); + } +} diff --git a/src/Models/Auth/Role.php b/src/Models/Auth/Role.php new file mode 100644 index 00000000..ede93ae1 --- /dev/null +++ b/src/Models/Auth/Role.php @@ -0,0 +1,71 @@ +belongsToMany(Permission::class) + ->withTimestamps(); + } + + /** + * The teams that that have the role assigned + * + * @return BelongsToMany + */ + public function teams() + { + return $this + ->belongsToMany(Team::class) + ->withTimestamps(); + } + + /** + * The users that that have the role assigned + * + * @return HasManyDeep + */ + public function users() + { + return $this->hasManyDeepFromRelations($this->teams(), (new Team)->users()); + } +} -- cgit v1.2.3-54-g00ecf