File: /var/www/matriculas_api_dev/app/Repositories/PermissionRepository.php
<?php
namespace App\Repositories;
use App\Models\Permission;
class PermissionRepository
{
public function getAll()
{
return Permission::where('deleted', false)
->orderBy('category', 'asc')
->orderBy('order', 'asc')
->get();
}
public function getAllGroupedByCategory()
{
$permissions = $this->getAll();
return $permissions->groupBy('category')->map(function ($group) {
return $group->sortBy('order')->values();
});
}
public function getById($id)
{
return Permission::where('deleted', false)->find($id);
}
public function getByCode($code)
{
return Permission::where('code', $code)
->where('deleted', false)
->first();
}
}