[WIP] Fix ergonomics rules
This commit is contained in:
85
app/Repositories/Core/Auth/Permissions.php
Normal file
85
app/Repositories/Core/Auth/Permissions.php
Normal file
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Core\Auth;
|
||||
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Laratrust\Traits\LaratrustUserTrait;
|
||||
use Yajra\DataTables\DataTables;
|
||||
|
||||
use App\Models\Core\Auth\Permission;
|
||||
|
||||
class Permissions
|
||||
{
|
||||
public static function getModules()
|
||||
{
|
||||
return Permission::select('module')->distinct('module')->get()->pluck('module');
|
||||
}
|
||||
|
||||
public static function getOptions()
|
||||
{
|
||||
return Permission::orderBy('name', 'asc')->get()->pluck('name', 'id')->toArray();
|
||||
}
|
||||
|
||||
public static function getInfo($id)
|
||||
{
|
||||
return Permission::find($id);
|
||||
}
|
||||
|
||||
public static function select_all()
|
||||
{
|
||||
return self::getAll()->toArray();
|
||||
}
|
||||
|
||||
public static function select_by_id($id)
|
||||
{
|
||||
return Permission::find($id)->toArray();
|
||||
}
|
||||
|
||||
public static function getAll()
|
||||
{
|
||||
return Permission::orderBy('name', 'asc')->get();
|
||||
}
|
||||
|
||||
public static function getByName($name)
|
||||
{
|
||||
return Permission::where('name', $name)->first();
|
||||
}
|
||||
|
||||
public static function get($id)
|
||||
{
|
||||
return Permission::find($id);
|
||||
}
|
||||
|
||||
public static function getTable($id)
|
||||
{
|
||||
$datas = Permission::withCount(['users']);
|
||||
return Datatables::of($datas)->make(true);
|
||||
}
|
||||
|
||||
public static function delete($id)
|
||||
{
|
||||
Users::destroyByUniquePermission($id);
|
||||
return Permission::destroy($id);
|
||||
}
|
||||
|
||||
public static function store($data)
|
||||
{
|
||||
return (isset($data['id']) && $data['id']) ? self::update($data) : self::create($data);
|
||||
}
|
||||
|
||||
public static function create($data)
|
||||
{
|
||||
return Permission::create($data);
|
||||
}
|
||||
|
||||
public static function update($data)
|
||||
{
|
||||
return Permission::find($data['id'])->update($data);
|
||||
}
|
||||
|
||||
public static function count()
|
||||
{
|
||||
return Permission::count();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user