mirror of
https://github.com/PhyreApps/PhyrePanel.git
synced 2024-11-25 09:00:27 +00:00
update
This commit is contained in:
parent
29b1ba8407
commit
aab1b8128e
3 changed files with 100 additions and 3 deletions
|
@ -3,6 +3,8 @@
|
|||
namespace Modules\Customer\App\Filament\Resources;
|
||||
|
||||
use App\Models\Database;
|
||||
use App\Models\HostingSubscription;
|
||||
use App\Models\RemoteDatabaseServer;
|
||||
use Modules\Customer\App\Filament\Resources\DatabaseResource\Pages;
|
||||
use Modules\Customer\App\Filament\Resources\DatabaseResource\RelationManagers;
|
||||
use Filament\Forms;
|
||||
|
@ -21,10 +23,94 @@ class DatabaseResource extends Resource
|
|||
|
||||
public static function form(Form $form): Form
|
||||
{
|
||||
$systemUsername = '';
|
||||
if ($form->getRecord()) {
|
||||
$systemUsername = $form->getRecord()->hostingSubscription->system_username;
|
||||
}
|
||||
|
||||
return $form
|
||||
->schema([
|
||||
//
|
||||
]);
|
||||
|
||||
Forms\Components\Select::make('hosting_subscription_id')
|
||||
->label('Hosting Subscription')
|
||||
->options(
|
||||
\App\Models\HostingSubscription::all()->pluck('domain', 'id')
|
||||
)
|
||||
->live()
|
||||
->afterStateUpdated(function (Forms\Components\Select $component) use($systemUsername) {
|
||||
$findHostingSubscription = HostingSubscription::select(['system_username'])
|
||||
->where('id', $component->getState())
|
||||
->first();
|
||||
if ($findHostingSubscription) {
|
||||
$systemUsername = $findHostingSubscription->system_username;
|
||||
}
|
||||
})
|
||||
->disabled(function ($record) {
|
||||
return $record;
|
||||
})
|
||||
->required(),
|
||||
|
||||
Forms\Components\ToggleButtons::make('is_remote_database_server')
|
||||
->default(0)
|
||||
->disabled(function ($record) {
|
||||
return $record;
|
||||
})
|
||||
->live()
|
||||
->options([
|
||||
0 => 'Internal',
|
||||
1 => 'Remote Database Server',
|
||||
])->inline(),
|
||||
|
||||
Forms\Components\Select::make('remote_database_server_id')
|
||||
->label('Remote Database Server')
|
||||
->hidden(fn(Forms\Get $get): bool => '1' !== $get('is_remote_database_server'))
|
||||
->options(
|
||||
RemoteDatabaseServer::all()->pluck('name', 'id')
|
||||
),
|
||||
|
||||
Forms\Components\TextInput::make('database_name')
|
||||
->prefix(function ($record) use($systemUsername) {
|
||||
if ($record) {
|
||||
return $record->database_prefix;
|
||||
}
|
||||
if (!$systemUsername) {
|
||||
return false;
|
||||
}
|
||||
return $systemUsername.'_';
|
||||
})
|
||||
->disabled(function ($record) {
|
||||
return $record;
|
||||
})
|
||||
->label('Database Name')
|
||||
->required(),
|
||||
|
||||
Forms\Components\Repeater::make('databaseUsers')
|
||||
->relationship('databaseUsers')
|
||||
->schema([
|
||||
Forms\Components\TextInput::make('username')
|
||||
->disabled(function ($record) {
|
||||
return $record;
|
||||
})
|
||||
->prefix(function ($record) use($systemUsername) {
|
||||
if ($record) {
|
||||
return $record->username_prefix;
|
||||
}
|
||||
if (!$systemUsername) {
|
||||
return false;
|
||||
}
|
||||
return $systemUsername.'_';
|
||||
})
|
||||
->required(),
|
||||
Forms\Components\TextInput::make('password')
|
||||
->disabled(function ($record) {
|
||||
return $record;
|
||||
})
|
||||
//->password()
|
||||
->required(),
|
||||
])
|
||||
->columns(2)
|
||||
|
||||
])->columns(1);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
|
|
|
@ -25,7 +25,7 @@ class Database extends Model
|
|||
protected static function booted(): void
|
||||
{
|
||||
static::addGlobalScope('customer', function (Builder $query) {
|
||||
if (auth()->check()) {
|
||||
if (auth()->check() && auth()->guard()->name == 'web_customer') {
|
||||
$query->whereHas('hostingSubscription', function ($query) {
|
||||
$query->where('customer_id', auth()->user()->id);
|
||||
});
|
||||
|
|
|
@ -4,6 +4,7 @@ namespace App\Models;
|
|||
|
||||
use App\Actions\CreateLinuxWebUser;
|
||||
use App\Actions\GetLinuxUser;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Str;
|
||||
|
@ -26,6 +27,16 @@ class HostingSubscription extends Model
|
|||
'renewal_date',
|
||||
];
|
||||
|
||||
protected static function booted(): void
|
||||
{
|
||||
static::addGlobalScope('customer', function (Builder $query) {
|
||||
if (auth()->check() && auth()->guard()->name == 'web_customer') {
|
||||
$query->where('customer_id', auth()->user()->id);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public static function boot()
|
||||
{
|
||||
parent::boot();
|
||||
|
|
Loading…
Reference in a new issue