Update Database.php

This commit is contained in:
Bozhidar 2024-04-26 18:28:28 +03:00
parent 30e0009b94
commit 29b1ba8407

View file

@ -7,6 +7,7 @@ use App\UniversalDatabaseExecutor;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Str;
use Illuminate\Database\Eloquent\Builder;
class Database extends Model
{
@ -21,6 +22,17 @@ class Database extends Model
'description',
];
protected static function booted(): void
{
static::addGlobalScope('customer', function (Builder $query) {
if (auth()->check()) {
$query->whereHas('hostingSubscription', function ($query) {
$query->where('customer_id', auth()->user()->id);
});
}
});
}
public static function boot()
{
parent::boot();