TRF Certest first commit
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
namespace Vanguard\Repositories\Permission;
|
||||
|
||||
use Cache;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Vanguard\Events\Permission\Created;
|
||||
use Vanguard\Events\Permission\Deleted;
|
||||
use Vanguard\Events\Permission\Updated;
|
||||
use Vanguard\Permission;
|
||||
|
||||
class EloquentPermission implements PermissionRepository
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function all(): Collection
|
||||
{
|
||||
return Permission::all();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function find($id): Permission
|
||||
{
|
||||
return Permission::find($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function create(array $data): Permission
|
||||
{
|
||||
$permission = Permission::create($data);
|
||||
|
||||
event(new Created($permission));
|
||||
|
||||
return $permission;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function update($id, array $data): Permission
|
||||
{
|
||||
$permission = $this->find($id);
|
||||
|
||||
$permission->update($data);
|
||||
|
||||
Cache::flush();
|
||||
|
||||
event(new Updated($permission));
|
||||
|
||||
return $permission;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function delete($id): bool
|
||||
{
|
||||
$permission = $this->find($id);
|
||||
|
||||
event(new Deleted($permission));
|
||||
|
||||
$status = $permission->delete();
|
||||
|
||||
Cache::flush();
|
||||
|
||||
return $status;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace Vanguard\Repositories\Permission;
|
||||
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Vanguard\Permission;
|
||||
|
||||
interface PermissionRepository
|
||||
{
|
||||
/**
|
||||
* Get all system permissions.
|
||||
*
|
||||
* @return Collection<Permission>
|
||||
*/
|
||||
public function all(): Collection;
|
||||
|
||||
/**
|
||||
* Finds the permission by given id.
|
||||
*/
|
||||
public function find(int $id): Permission;
|
||||
|
||||
/**
|
||||
* Creates new permission from provided data.
|
||||
*/
|
||||
public function create(array $data): Permission;
|
||||
|
||||
/**
|
||||
* Updates specified permission.
|
||||
*/
|
||||
public function update(int $id, array $data): Permission;
|
||||
|
||||
/**
|
||||
* Remove specified permission from repository.
|
||||
*/
|
||||
public function delete($id): bool;
|
||||
}
|
||||
Reference in New Issue
Block a user