Skip to content

Instantly share code, notes, and snippets.

@szabomikierno
Last active December 28, 2017 16:06
Show Gist options
  • Select an option

  • Save szabomikierno/da0d049b63bd71504cc2e9e0f27781d5 to your computer and use it in GitHub Desktop.

Select an option

Save szabomikierno/da0d049b63bd71504cc2e9e0f27781d5 to your computer and use it in GitHub Desktop.
User resource management policy
<?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