Skip to content

Commit

Permalink
fix: edge case with named permissions makes hasPermssion fail
Browse files Browse the repository at this point in the history
  • Loading branch information
uwla committed Dec 11, 2024
1 parent c88c812 commit 0bf840a
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/Models/Permission.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,17 @@ public static function getByName($names, $modelType = null, $models = null): Col
$models = $models->pluck('id');
}

// each resource is identified by its model_id
$query->where(function ($q) use ($names, $models, $permission_count) {
// Each resource is identified by its model_id.
// We will build a query that looks like this:
// WHERE ((name = ? AND id = ?) OR (name = ? AND id = ?) OR ... )
$q1 = $query;
$q1->where(function ($q2) use ($names, $models, $permission_count) {
for ($i = 0; $i < $permission_count; $i += 1) {
$q->orWhere([
['name', $names[$i]],
['model_id', $models[$i]],
]);
}
$q2->orWhere(function ($q3) use ($names, $models, $i) {
$q3->where('name', $names[$i])
->where('model_id', $models[$i]);
});
};
});

return $query->get();
Expand Down

0 comments on commit 0bf840a

Please sign in to comment.