12-05-2026 Frontend dev
This commit is contained in:
parent
405df0a122
commit
5b8bdf4182
779 changed files with 480564 additions and 6241 deletions
37
app/Scopes/PortalScope.php
Normal file
37
app/Scopes/PortalScope.php
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
|
||||
namespace App\Scopes;
|
||||
|
||||
use App\Enums\Portal;
|
||||
use App\Services\CurrentPortalContext;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Scope;
|
||||
|
||||
/**
|
||||
* Filtert Eloquent-Queries automatisch auf das aktive Portal.
|
||||
*
|
||||
* Einträge mit portal = 'both' sind immer sichtbar.
|
||||
* Kein Filter wenn: kein Portal-Kontext gesetzt (CLI, Tests, Import-Commands).
|
||||
*
|
||||
* Deaktivieren für einzelne Queries:
|
||||
* Company::withoutGlobalScope(PortalScope::class)->get();
|
||||
*/
|
||||
class PortalScope implements Scope
|
||||
{
|
||||
public function apply(Builder $builder, Model $model): void
|
||||
{
|
||||
$portal = CurrentPortalContext::get();
|
||||
|
||||
if ($portal === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
$table = $model->getTable();
|
||||
|
||||
$builder->where(function (Builder $q) use ($table, $portal): void {
|
||||
$q->where("{$table}.portal", $portal->value)
|
||||
->orWhere("{$table}.portal", Portal::Both->value);
|
||||
});
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue