mirror of
https://github.com/PhyreApps/PhyrePanel.git
synced 2024-09-19 23:31:12 +00:00
update
This commit is contained in:
parent
c4fa067577
commit
ed8b0fb50d
|
@ -4,6 +4,7 @@ namespace Modules\Customer\App\Filament\Resources;
|
|||
|
||||
use App\Models\Domain;
|
||||
use App\Models\GitSshKey;
|
||||
use App\Models\Scopes\CustomerScope;
|
||||
use Modules\Customer\App\Filament\Resources\GitSshKeyResource\Pages;
|
||||
use Modules\Customer\App\Filament\Resources\GitSshKeyResource\RelationManagers;
|
||||
use Filament\Forms;
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
namespace App\Models;
|
||||
|
||||
use App\GitClient;
|
||||
use App\Models\Scopes\CustomerDomainScope;
|
||||
use App\Models\Scopes\CustomerHostingSubscriptionScope;
|
||||
use App\ShellApi;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
@ -37,6 +39,15 @@ class GitRepository extends Model
|
|||
'domain_id',
|
||||
'git_ssh_key_id',
|
||||
];
|
||||
|
||||
/**
|
||||
* The "booted" method of the model.
|
||||
*/
|
||||
protected static function booted(): void
|
||||
{
|
||||
static::addGlobalScope(new CustomerDomainScope());
|
||||
}
|
||||
|
||||
public static function boot()
|
||||
{
|
||||
parent::boot();
|
||||
|
|
|
@ -2,6 +2,9 @@
|
|||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Models\Scopes\CustomerScope;
|
||||
use App\Models\Scopes\CustomerHostingSubscriptionScope;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
|
@ -16,6 +19,14 @@ class GitSshKey extends Model
|
|||
'public_key',
|
||||
];
|
||||
|
||||
/**
|
||||
* The "booted" method of the model.
|
||||
*/
|
||||
protected static function booted(): void
|
||||
{
|
||||
static::addGlobalScope(new CustomerHostingSubscriptionScope());
|
||||
}
|
||||
|
||||
public function hostingSubscription()
|
||||
{
|
||||
return $this->belongsTo(HostingSubscription::class);
|
||||
|
|
27
web/app/Models/Scopes/CustomerDomainScope.php
Normal file
27
web/app/Models/Scopes/CustomerDomainScope.php
Normal file
|
@ -0,0 +1,27 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models\Scopes;
|
||||
|
||||
use App\Models\Domain;
|
||||
use App\Models\HostingSubscription;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Scope;
|
||||
|
||||
class CustomerDomainScope implements Scope
|
||||
{
|
||||
/**
|
||||
* Apply the scope to a given Eloquent query builder.
|
||||
*/
|
||||
public function apply(Builder $builder, Model $model): void
|
||||
{
|
||||
if (auth()->check() && auth()->guard()->name == 'web_customer') {
|
||||
|
||||
$findHostingSubscriptionIds = HostingSubscription::where('customer_id', auth()->user()->id)->pluck('id');
|
||||
$findDomainIds = Domain::whereIn('hosting_subscription_id', $findHostingSubscriptionIds)->pluck('id');
|
||||
|
||||
$builder->whereIn('domain_id', $findDomainIds);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
23
web/app/Models/Scopes/CustomerHostingSubscriptionScope.php
Normal file
23
web/app/Models/Scopes/CustomerHostingSubscriptionScope.php
Normal file
|
@ -0,0 +1,23 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models\Scopes;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Scope;
|
||||
|
||||
class CustomerHostingSubscriptionScope implements Scope
|
||||
{
|
||||
/**
|
||||
* Apply the scope to a given Eloquent query builder.
|
||||
*/
|
||||
public function apply(Builder $builder, Model $model): void
|
||||
{
|
||||
if (auth()->check() && auth()->guard()->name == 'web_customer') {
|
||||
$builder->whereHas('hostingSubscription', function ($query) {
|
||||
$query->where('customer_id', auth()->user()->id);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
20
web/app/Models/Scopes/CustomerScope.php
Normal file
20
web/app/Models/Scopes/CustomerScope.php
Normal file
|
@ -0,0 +1,20 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models\Scopes;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Scope;
|
||||
|
||||
class CustomerScope implements Scope
|
||||
{
|
||||
/**
|
||||
* Apply the scope to a given Eloquent query builder.
|
||||
*/
|
||||
public function apply(Builder $builder, Model $model): void
|
||||
{
|
||||
if (auth()->check() && auth()->guard()->name == 'web_customer') {
|
||||
$builder->where('customer_id', auth()->user()->id);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue