First complete upload on nas
This commit is contained in:
@@ -0,0 +1,99 @@
|
||||
<?php
|
||||
|
||||
namespace Vanguard\Repositories\Role;
|
||||
|
||||
use Vanguard\Events\Role\Created;
|
||||
use Vanguard\Events\Role\Deleted;
|
||||
use Vanguard\Events\Role\Updated;
|
||||
use Vanguard\Role;
|
||||
|
||||
class EloquentRole implements RoleRepository
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function all()
|
||||
{
|
||||
return Role::all();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getAllWithUsersCount()
|
||||
{
|
||||
return Role::withCount('users')->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function find($id)
|
||||
{
|
||||
return Role::find($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function create(array $data)
|
||||
{
|
||||
$role = Role::create($data);
|
||||
|
||||
event(new Created($role));
|
||||
|
||||
return $role;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function update($id, array $data)
|
||||
{
|
||||
$role = $this->find($id);
|
||||
|
||||
$role->update($data);
|
||||
|
||||
event(new Updated($role));
|
||||
|
||||
return $role;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function delete($id)
|
||||
{
|
||||
$role = $this->find($id);
|
||||
|
||||
event(new Deleted($role));
|
||||
|
||||
return $role->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function updatePermissions($roleId, array $permissions)
|
||||
{
|
||||
$role = $this->find($roleId);
|
||||
|
||||
$role->syncPermissions($permissions);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function lists($column = 'name', $key = 'id')
|
||||
{
|
||||
return Role::pluck($column, $key);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function findByName($name)
|
||||
{
|
||||
return Role::where('name', $name)->first();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
|
||||
namespace Vanguard\Repositories\Role;
|
||||
|
||||
use Vanguard\Role;
|
||||
|
||||
interface RoleRepository
|
||||
{
|
||||
/**
|
||||
* Get all system roles.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Collection
|
||||
*/
|
||||
public function all();
|
||||
|
||||
/**
|
||||
* Lists all system roles into $key => $column value pairs.
|
||||
*
|
||||
* @param string $column
|
||||
* @param string $key
|
||||
* @return mixed
|
||||
*/
|
||||
public function lists($column = 'name', $key = 'id');
|
||||
|
||||
/**
|
||||
* Get all system roles with number of users for each role.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getAllWithUsersCount();
|
||||
|
||||
/**
|
||||
* Find system role by id.
|
||||
*
|
||||
* @param $id Role Id
|
||||
* @return Role|null
|
||||
*/
|
||||
public function find($id);
|
||||
|
||||
/**
|
||||
* Find role by name:
|
||||
*
|
||||
* @param $name
|
||||
* @return mixed
|
||||
*/
|
||||
public function findByName($name);
|
||||
|
||||
/**
|
||||
* Create new system role.
|
||||
*
|
||||
* @param array $data
|
||||
* @return Role
|
||||
*/
|
||||
public function create(array $data);
|
||||
|
||||
/**
|
||||
* Update specified role.
|
||||
*
|
||||
* @param $id Role Id
|
||||
* @param array $data
|
||||
* @return Role
|
||||
*/
|
||||
public function update($id, array $data);
|
||||
|
||||
/**
|
||||
* Remove role from repository.
|
||||
*
|
||||
* @param $id Role Id
|
||||
* @return bool
|
||||
*/
|
||||
public function delete($id);
|
||||
|
||||
/**
|
||||
* Update the permissions for given role.
|
||||
*
|
||||
* @param $roleId
|
||||
* @param array $permissions
|
||||
* @return mixed
|
||||
*/
|
||||
public function updatePermissions($roleId, array $permissions);
|
||||
}
|
||||
Reference in New Issue
Block a user