Files
root e13df69885
API CI/CD / Validate (composer + pint) (push) Successful in 3m6s
API CI/CD / Test (PHPUnit) (push) Failing after 4m53s
API CI/CD / Build frontend assets (push) Successful in 1m2s
API CI/CD / Security audit (push) Failing after 59s
API CI/CD / Deploy to shared hosting (PHP) (push) Has been skipped
fix unittests issues
2026-07-07 20:56:32 -04:00

59 lines
1.6 KiB
PHP

<?php
namespace App\Models;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
class Permission extends BaseModel
{
protected $table = 'permissions';
// ✅ legacy: useTimestamps = true (created_at/updated_at)
public $timestamps = true;
protected $fillable = ['name', 'description', 'created_at', 'updated_at'];
/* =========================
* legacy method equivalents
* ========================= */
/**
* Fetch all permissions from the database.
*/
public static function getPermissions()
{
try {
return static::query()->get();
} catch (\Throwable $e) {
Log::error('Error fetching permissions: '.$e->getMessage());
throw $e;
}
}
/**
* Fetch permissions assigned to a specific role.
* Returns rows similar to legacy:
* role_permissions.* + permissions.name
*/
public static function getRolePermissions(int $roleId): array
{
try {
$rows = DB::table('role_permissions')
->leftJoin('permissions', 'role_permissions.permission_id', '=', 'permissions.id')
->where('role_permissions.role_id', $roleId)
->select('role_permissions.*', 'permissions.name')
->get()
->map(fn ($r) => (array) $r)
->all();
Log::info('Role permissions fetched: '.print_r($rows, true));
return $rows;
} catch (\Throwable $e) {
Log::error("Error fetching role permissions for role ID {$roleId}: ".$e->getMessage());
throw $e;
}
}
}