Override the default bouncer scope class with a temporary hotfix to the roles issue

This commit is contained in:
gdarko
2024-02-18 00:13:24 +01:00
parent 1c7274287d
commit e73ab3d4ee
2 changed files with 36 additions and 3 deletions

View File

@@ -2,7 +2,37 @@
namespace InvoiceShelf\Bouncer\Scopes;
class DefaultScope
{
use Silber\Bouncer\Database\Scope\Scope;
class DefaultScope extends Scope
{
public function applyToModelQuery($query, $table = null)
{
if (is_null($this->scope) || $this->onlyScopeRelations) {
return $query;
}
if (is_null($table)) {
$table = $query->getModel()->getTable();
}
return $this->applyToQuery($query, $table);
}
public function applyToRelationQuery($query, $table)
{
if (is_null($this->scope)) {
return $query;
}
return $this->applyToQuery($query, $table);
}
protected function applyToQuery($query, $table)
{
return $query->where(function ($query) use ($table) {
$query->where("{$table}.scope", $this->scope)
->orWhereNull("{$table}.scope");
});
}
}