44 lines
854 B
PHP
44 lines
854 B
PHP
<?php
|
|
|
|
namespace Modules\User\Repositories;
|
|
|
|
use Spatie\Permission\Models\Role;
|
|
|
|
class RoleRepository implements RoleInterface
|
|
{
|
|
public function pluck()
|
|
{
|
|
return Role::pluck('name', 'id');
|
|
}
|
|
|
|
public function findAll()
|
|
{
|
|
return Role::with('permissions')->get();
|
|
}
|
|
|
|
public function getRoleById($roleId)
|
|
{
|
|
return Role::with('permissions')->findOrFail($roleId);
|
|
}
|
|
|
|
public function delete($roleId)
|
|
{
|
|
$role = self::getRoleById($roleId);
|
|
$role->permissions()->detach();
|
|
return $role->delete();
|
|
}
|
|
|
|
public function create(array $roleDetails)
|
|
{
|
|
return Role::create($roleDetails);
|
|
}
|
|
|
|
public function update($roleId, array $newDetails)
|
|
{
|
|
$role = Role::find($roleId);
|
|
$role->update($newDetails);
|
|
return $role;
|
|
}
|
|
|
|
}
|