Move Bouncer DefaultScope from app/Bouncer to app/Support/BouncerDefaultScope

This commit is contained in:
Darko Gjorgjijoski
2026-04-03 19:21:56 +02:00
parent 4f47db9258
commit 00599b6943
2 changed files with 4 additions and 4 deletions

View File

@@ -0,0 +1,38 @@
<?php
namespace App\Support;
use Silber\Bouncer\Database\Scope\Scope;
class BouncerDefaultScope 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");
});
}
}