Initial commit
This commit is contained in:
26
app/Services/UserScopeApplier.php
Normal file
26
app/Services/UserScopeApplier.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Models\Contracts\BelongsToUser;
|
||||
use App\Models\Scopes\UserScope;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
final class UserScopeApplier
|
||||
{
|
||||
private bool $enabled = false;
|
||||
|
||||
public function enable(): void
|
||||
{
|
||||
$this->enabled = true;
|
||||
}
|
||||
|
||||
public function applyScope(Model $model): void
|
||||
{
|
||||
if ($this->enabled && $model instanceof BelongsToUser) {
|
||||
$model->addGlobalScope(new UserScope());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user