mirror of
https://github.com/InvoiceShelf/InvoiceShelf.git
synced 2026-04-18 18:54:07 +00:00
Move Bouncer DefaultScope from app/Bouncer to app/Support/BouncerDefaultScope
This commit is contained in:
38
app/Support/BouncerDefaultScope.php
Normal file
38
app/Support/BouncerDefaultScope.php
Normal 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");
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user