mirror of
https://github.com/InvoiceShelf/InvoiceShelf.git
synced 2026-04-07 13:41:23 +00:00
38
app/Bouncer/Scopes/DefaultScope.php
Normal file
38
app/Bouncer/Scopes/DefaultScope.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace InvoiceShelf\Bouncer\Scopes;
|
||||
|
||||
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");
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,9 @@ namespace InvoiceShelf\Providers;
|
||||
|
||||
use Illuminate\Pagination\Paginator;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use InvoiceShelf\Bouncer\Scopes\DefaultScope;
|
||||
use InvoiceShelf\Space\InstallUtils;
|
||||
use Silber\Bouncer\Database\Models as BouncerModels;
|
||||
|
||||
class AppServiceProvider extends ServiceProvider
|
||||
{
|
||||
@@ -30,7 +32,7 @@ class AppServiceProvider extends ServiceProvider
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
//
|
||||
BouncerModels::scope(new DefaultScope);
|
||||
}
|
||||
|
||||
public function addMenus()
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
"lavary/laravel-menu": "^1.8",
|
||||
"league/flysystem-aws-s3-v3": "^3.23",
|
||||
"predis/predis": "^2.2",
|
||||
"silber/bouncer": "^v1.0",
|
||||
"silber/bouncer": "v1.0.1",
|
||||
"spatie/flysystem-dropbox": "^3.0",
|
||||
"spatie/laravel-backup": "^8.5",
|
||||
"spatie/laravel-medialibrary": "^10.15",
|
||||
|
||||
459
composer.lock
generated
459
composer.lock
generated
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user