Last active
December 28, 2017 16:06
-
-
Save szabomikierno/da0d049b63bd71504cc2e9e0f27781d5 to your computer and use it in GitHub Desktop.
User resource management policy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| namespace App\Infrastructure\Policies; | |
| use App\Infrastructure\Model\User; | |
| use App\Infrastructure\Utility\ResourcePolicy; | |
| class UserPolicy extends ResourcePolicy | |
| { | |
| private $user; | |
| public function __construct() | |
| { | |
| parent::__construct(); | |
| $this->user=\Request::route('user'); | |
| } | |
| protected function show() | |
| { | |
| return true; | |
| } | |
| protected function store() | |
| { | |
| // if not logged in | |
| if(!$this->executor) | |
| return true; | |
| else | |
| return | |
| //if admin has right | |
| $this->executor->adminRights->where('code', 'create-user')->first(); | |
| } | |
| protected function destroy() | |
| { | |
| return | |
| //if admin has the right | |
| $this->executor->adminRights->where('code', 'delete-user')->first() || | |
| //if i am the user | |
| $this->user->id == $this->executor->id; | |
| } | |
| protected function update () | |
| { | |
| return | |
| //if admin has the right | |
| $this->executor->adminRights->where('code', 'update-user')->first() || | |
| //if i am the user | |
| $this->user->id == $this->executor->id; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment