diff --git a/app/Models/User.php b/app/Models/User.php index 6589520..bde9397 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -45,4 +45,24 @@ class User extends Authenticatable 'email_verified_at' => 'datetime', 'password' => 'hashed', ]; + + /** + * User is me? + */ + public function isMe(): bool + { + return $this->email === 'nurmuhammet@mail.com'; + } + + /** + * Is user admin? + */ + public function isAdmin(): bool + { + if ($this->isMe()) { + return true; + } + + return $this->hasRole(['king', 'superadmin', 'admin']); + } } diff --git a/app/Policies/Branch/BranchPolicy.php b/app/Policies/Branch/BranchPolicy.php new file mode 100644 index 0000000..390c4bc --- /dev/null +++ b/app/Policies/Branch/BranchPolicy.php @@ -0,0 +1,66 @@ +isAdmin()) { + return true; + } + + return false; + } + + /** + * Determine whether the user can view the model. + */ + public function view(User $user, User $model): bool + { + if ($model->email === 'nurmuhammet@mail.com') { + return $user->isMe(); + } + + if ($user->isAdmin()) { + return true; + } + + return false; + } + + /** + * Determine whether the user can create models. + */ + public function create(User $user): bool + { + if ($user->isAdmin()) { + return true; + } + + return false; + } + + /** + * Determine whether the user can update the model. + */ + public function update(User $user, User $model): bool + { + if ($model->email === 'nurmuhammet@mail.com') { + return $user->isMe(); + } + + if ($user->isAdmin()) { + return true; + } + + return false; + } + + /** + * Determine whether the user can delete the model. + */ + public function delete(User $user, User $model): bool + { + if ($model->email === 'nurmuhammet@mail.com') { + return false; + } + + if ($user->isAdmin()) { + return true; + } + + return false; + } + + /** + * Determine whether the user can restore the model. + */ + public function restore(User $user, User $model): bool + { + if ($user->isAdmin()) { + return true; + } + + return false; + } + + /** + * Determine whether the user can permanently delete the model. + */ + public function forceDelete(User $user, User $model): bool + { + if ($user->isAdmin()) { + return true; + } + + return false; + } +}