Compare commits
84 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6b6435f71b | ||
|
|
a838f1a1da | ||
|
|
9535f03ff1 | ||
|
|
879fe90f18 | ||
|
|
9e79b4d3c1 | ||
|
|
f8929e5622 | ||
|
|
6556cf017a | ||
|
|
514c010804 | ||
|
|
b3a5624ad4 | ||
|
|
3857aa33d2 | ||
|
|
c625a5c967 | ||
|
|
b4d35adfb4 | ||
|
|
0c1d970a9c | ||
|
|
3df600bcda | ||
|
|
c9e0bb3bda | ||
|
|
3aae5068ce | ||
|
|
255353763f | ||
|
|
99a49848ca | ||
|
|
def9e3c722 | ||
|
|
6cc46cf652 | ||
|
|
9ac72ffda8 | ||
|
|
3f1bdb1d8e | ||
|
|
f3d2b0c71f | ||
|
|
4071ba6d49 | ||
|
|
4ec50d7ca1 | ||
|
|
51b7f28634 | ||
|
|
7f6b59cd4f | ||
|
|
80b4428b72 | ||
|
|
010ecd63ac | ||
|
|
741104de05 | ||
|
|
5254ca3ebe | ||
|
|
aefbb5be33 | ||
|
|
d22bb52f35 | ||
|
|
088d951bea | ||
|
|
01fe642a9d | ||
|
|
258e7127f7 | ||
|
|
7e44db0e56 | ||
|
|
e1c07d84df | ||
|
|
145a4af407 | ||
|
|
d1a7b6002a | ||
|
|
a9c0bdee34 | ||
|
|
604b535895 | ||
|
|
c67546b949 | ||
|
|
0a45a1c8b2 | ||
|
|
3cd83ad69c | ||
|
|
d27df25b3c | ||
|
|
e55e984f98 | ||
|
|
5fbc0e0a37 | ||
|
|
3313786480 | ||
|
|
5ed532535b | ||
|
|
a8361f7b22 | ||
|
|
a190ccf8dc | ||
|
|
3f927f9ec1 | ||
|
|
33692960ff | ||
|
|
1f79a4e790 | ||
|
|
903e1cccc6 | ||
|
|
3f7f6206bd | ||
|
|
be00824f59 | ||
|
|
eb4220adc9 | ||
|
|
3562a60461 | ||
|
|
4d80f26519 | ||
|
|
29dc893806 | ||
|
|
35abe4cfd7 | ||
|
|
275b359b53 | ||
|
|
0be4f4cd94 | ||
|
|
2ffd09877e | ||
|
|
a5d2445e3f | ||
|
|
92631cdee9 | ||
|
|
0f63b8153a | ||
|
|
b6983d5377 | ||
|
|
78899bef61 | ||
|
|
9397651515 | ||
|
|
f692fb681a | ||
|
|
6de17d3e3c | ||
|
|
b2b24db2e6 | ||
|
|
2af546643e | ||
|
|
e63b13e5fd | ||
|
|
36385c2242 | ||
|
|
ed67a44f5f | ||
|
|
fb8b2fa935 | ||
|
|
6e1b7613e4 | ||
|
|
175b104ebc | ||
|
|
a72a2466ef | ||
|
|
9952e2226d |
@@ -9,6 +9,8 @@ APP_DATE_TIME_FORMAT="Y-m-d H:i:s"
|
||||
PLOI_TOKEN=
|
||||
PLOI_CORE_TOKEN=
|
||||
|
||||
IMPERSONATION=false
|
||||
|
||||
LOG_CHANNEL=stack
|
||||
|
||||
DB_CONNECTION=mysql
|
||||
|
||||
42
.github/workflows/master.yml
vendored
42
.github/workflows/master.yml
vendored
@@ -1,42 +0,0 @@
|
||||
name: Run tests & build files
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
|
||||
jobs:
|
||||
test:
|
||||
name: Run tests
|
||||
uses: ./.github/workflows/run-tests.yml
|
||||
|
||||
deploy:
|
||||
needs: test
|
||||
name: Prepare build assets
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Setup PHP with PECL extension
|
||||
uses: shivammathur/setup-php@v2
|
||||
with:
|
||||
php-version: '8.1'
|
||||
extensions: pcntl
|
||||
|
||||
- run: composer install
|
||||
name: Install dependencies
|
||||
|
||||
- name: Set up Node
|
||||
uses: actions/setup-node@v1
|
||||
with:
|
||||
node-version: '14.x'
|
||||
- run: npm install
|
||||
- run: npm run prod
|
||||
- run: npm run prod:filament
|
||||
|
||||
- name: Commit build assets
|
||||
run: |
|
||||
git config --local user.email "actions@github.com"
|
||||
git config --local user.name "GitHub Actions"
|
||||
git add .
|
||||
git commit -m "Updated build assets"
|
||||
git push origin
|
||||
2
.github/workflows/run-tests.yml
vendored
2
.github/workflows/run-tests.yml
vendored
@@ -11,7 +11,7 @@ jobs:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
os: [ubuntu-latest]
|
||||
php: [8.1]
|
||||
php: [8.2]
|
||||
|
||||
runs-on: ${{ matrix.os }}
|
||||
steps:
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# Ploi Core
|
||||
|
||||
With Ploi Core, you'll power-launch your webhosting company.
|
||||
With Ploi Core, you'll power-launch your webhosting company.
|
||||
Using the ploi.io system as backbone you will be able to serve your customers your custom panel & feeling.
|
||||
|
||||
<p align="center"><img src="https://ploi-core.io/images/og.jpg" width="100%"></p>
|
||||
@@ -17,4 +17,4 @@ https://ploi.io
|
||||
|
||||
The contribution guide can be found inside our documentation:
|
||||
|
||||
https://docs.ploi-core.io/getting-started/contribution-guide
|
||||
https://docs.ploi-core.io/261-getting-started/639-contribution-guide
|
||||
|
||||
@@ -2,30 +2,59 @@
|
||||
|
||||
namespace App\Actions\Server;
|
||||
|
||||
use Throwable;
|
||||
use App\Models\Server;
|
||||
use App\Services\Ploi\Ploi;
|
||||
use Filament\Notifications\Notification;
|
||||
|
||||
class SynchronizeServerAction
|
||||
{
|
||||
public function execute(int $ploiServerId): Server
|
||||
public function execute(int $ploiServerId): Server|null
|
||||
{
|
||||
$serverData = Ploi::make()->server()->get($ploiServerId)->getData();
|
||||
try {
|
||||
$serverData = Ploi::make()->server()->get($ploiServerId)->getData();
|
||||
} catch (Throwable $exception) {
|
||||
Notification::make()
|
||||
->title('An error has occurred: ' . $exception->getMessage())
|
||||
->danger()
|
||||
->send();
|
||||
|
||||
$server = Server::query()
|
||||
->updateOrCreate([
|
||||
'ploi_id' => $serverData->id,
|
||||
], [
|
||||
'status' => $serverData->status,
|
||||
'name' => $serverData->name,
|
||||
'ip' => $serverData->ip_address,
|
||||
'ssh_port' => $serverData->ssh_port,
|
||||
'internal_ip' => $serverData->internal_ip,
|
||||
'available_php_versions' => $serverData->installed_php_versions,
|
||||
]);
|
||||
return null;
|
||||
}
|
||||
|
||||
if(!$serverData){
|
||||
Notification::make()
|
||||
->title('Server synchronization')
|
||||
->body('It was not possible to synchronize servers, it seems the API key has the wrong scopes. Please make sure the Ploi API key you\'ve entered has all the scopes enabled.')
|
||||
->danger()
|
||||
->send();
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
$server = Server::query()
|
||||
->updateOrCreate([
|
||||
'ploi_id' => $serverData->id,
|
||||
], [
|
||||
'status' => $serverData->status,
|
||||
'name' => $serverData->name,
|
||||
'ip' => $serverData->ip_address,
|
||||
'ssh_port' => $serverData->ssh_port,
|
||||
'internal_ip' => $serverData->internal_ip,
|
||||
'available_php_versions' => $serverData->installed_php_versions,
|
||||
]);
|
||||
} catch (Throwable $exception) {
|
||||
Notification::make()
|
||||
->title('An error has occurred: ' . $exception->getMessage())
|
||||
->danger()
|
||||
->send();
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
Notification::make()
|
||||
->body(__('Server :server synchronized successfully.', ['server' => $server->name]))
|
||||
->title(__('Server :server synchronized successfully.', ['server' => $server->name]))
|
||||
->success()
|
||||
->send();
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ class SynchronizeSiteAction
|
||||
}
|
||||
|
||||
Notification::make()
|
||||
->body(__('Site :site synchronized successfully.', ['site' => $site->domain]))
|
||||
->title(__('Site :site synchronized successfully.', ['site' => $site->domain]))
|
||||
->success()
|
||||
->send();
|
||||
|
||||
|
||||
@@ -43,8 +43,8 @@ class Install extends Command
|
||||
$this->writeSeparationLine();
|
||||
$this->info('Make sure to also setup emailing, the cronjob and the queue worker.');
|
||||
$this->line(' ');
|
||||
$this->info('Setting up emailing: https://docs.ploi-core.io/getting-started/setting-up-email');
|
||||
$this->info('Setting up cronjob & queue worker: https://docs.ploi-core.io/getting-started/installation');
|
||||
$this->info('Setting up emailing: https://docs.ploi-core.io/261-getting-started/918-setting-up-email');
|
||||
$this->info('Setting up cronjob & queue worker: https://docs.ploi-core.io/261-getting-started/638-installation');
|
||||
$this->writeSeparationLine();
|
||||
$this->line(' ');
|
||||
$this->info('Visit your platform at ' . env('APP_URL'));
|
||||
|
||||
@@ -26,24 +26,17 @@ class ServerData extends Data
|
||||
public ?int $id = null,
|
||||
#[StringType]
|
||||
public ?string $status = null,
|
||||
#[StringType,
|
||||
AlphaDash,
|
||||
Max(40)]
|
||||
#[StringType, AlphaDash, Max(40)]
|
||||
public string $name,
|
||||
#[NotIn(0),
|
||||
Exists(Provider::class, 'id')]
|
||||
#[NotIn(0), Exists(Provider::class, 'id')]
|
||||
public int $provider_id,
|
||||
#[NotIn(0),
|
||||
Exists(ProviderRegion::class, 'id')]
|
||||
#[NotIn(0), Exists(ProviderRegion::class, 'id')]
|
||||
public int $provider_region_id,
|
||||
#[NotIn(0),
|
||||
Exists(ProviderPlan::class, 'id')]
|
||||
#[NotIn(0), Exists(ProviderPlan::class, 'id')]
|
||||
public int $provider_plan_id,
|
||||
#[StringType,
|
||||
In(['mysql', 'mariadb', 'postgresql', 'postgresql13'])]
|
||||
#[StringType, In(['mysql', 'mariadb', 'postgresql', 'postgresql13'])]
|
||||
public string $database_type,
|
||||
#[Exists(User::class, 'id'),
|
||||
IntegerType]
|
||||
#[Exists(User::class, 'id'), IntegerType]
|
||||
public ?int $user_id = null,
|
||||
public ?Carbon $created_at = null,
|
||||
) {
|
||||
|
||||
@@ -23,14 +23,11 @@ class SiteData extends Data
|
||||
public function __construct(
|
||||
public ?int $id = null,
|
||||
public ?string $status = null,
|
||||
#[Exists(Server::class, 'id'),
|
||||
IntegerType]
|
||||
#[Exists(Server::class, 'id'), IntegerType]
|
||||
public ?int $server_id = null,
|
||||
#[StringType,
|
||||
CustomRule(Hostname::class, ValidateMaximumSites::class)]
|
||||
#[StringType, CustomRule(Hostname::class, ValidateMaximumSites::class)]
|
||||
public ?string $domain = null,
|
||||
#[Exists(User::class, 'id'),
|
||||
IntegerType]
|
||||
#[Exists(User::class, 'id'), IntegerType]
|
||||
public ?int $user_id = null,
|
||||
public ?Carbon $created_at = null,
|
||||
) {
|
||||
|
||||
@@ -8,7 +8,7 @@ use Spatie\LaravelData\Support\DataProperty;
|
||||
|
||||
class CarbonCast implements Cast
|
||||
{
|
||||
public function cast(DataProperty $property, mixed $value): mixed
|
||||
public function cast(DataProperty $property, mixed $value, array $context): Carbon
|
||||
{
|
||||
return Carbon::parse($value);
|
||||
}
|
||||
|
||||
@@ -2,16 +2,13 @@
|
||||
|
||||
namespace App\DataTransferObjects\Support;
|
||||
|
||||
use Illuminate\Support\Enumerable;
|
||||
use Spatie\LaravelData\DataCollection;
|
||||
use Illuminate\Pagination\AbstractPaginator;
|
||||
use Illuminate\Contracts\Pagination\Paginator;
|
||||
use Illuminate\Pagination\AbstractCursorPaginator;
|
||||
|
||||
class Data extends \Spatie\LaravelData\Data
|
||||
{
|
||||
public static function collection(Paginator|Enumerable|array|AbstractCursorPaginator|DataCollection|AbstractPaginator $items): \App\DataTransferObjects\Support\DataCollection
|
||||
{
|
||||
return new \App\DataTransferObjects\Support\DataCollection(static::class, $items);
|
||||
}
|
||||
/**
|
||||
* When working with paginated data, we want to include pagination details in JSON
|
||||
* responses from the API. However, due to legacy requirements Ploi Core is using
|
||||
* a different structure than this package assumes. Therefore, we will override
|
||||
* the data collection, register a custom transformer and output the structure.
|
||||
*/
|
||||
protected static string $_paginatedCollectionClass = PaginatedDataCollection::class;
|
||||
}
|
||||
|
||||
@@ -2,14 +2,14 @@
|
||||
|
||||
namespace App\DataTransferObjects\Support;
|
||||
|
||||
use Illuminate\Support\Arr;
|
||||
|
||||
class DataCollectionTransformer extends \Spatie\LaravelData\Transformers\DataCollectionTransformer
|
||||
class DataCollectableTransformer extends \Spatie\LaravelData\Transformers\DataCollectableTransformer
|
||||
{
|
||||
protected function wrapPaginatedArray(array $paginated): array
|
||||
{
|
||||
$wrapKey = $this->wrap->getKey() ?? 'data';
|
||||
|
||||
return [
|
||||
'data' => $paginated['data'],
|
||||
$wrapKey => $paginated['data'],
|
||||
'links' => [
|
||||
'first' => $paginated['first_page_url'],
|
||||
'last' => $paginated['last_page_url'],
|
||||
@@ -27,14 +27,5 @@ class DataCollectionTransformer extends \Spatie\LaravelData\Transformers\DataCol
|
||||
'total' => $paginated['total'],
|
||||
],
|
||||
];
|
||||
|
||||
return [
|
||||
'data' => $paginated['data'],
|
||||
'links' => $paginated['links'] ?? [],
|
||||
'meta' => Arr::except($paginated, [
|
||||
'data',
|
||||
'links',
|
||||
]),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\DataTransferObjects\Support;
|
||||
|
||||
use Spatie\LaravelData\Support\TransformationType;
|
||||
|
||||
class DataCollection extends \Spatie\LaravelData\DataCollection
|
||||
{
|
||||
public function transform(TransformationType $type): array
|
||||
{
|
||||
$transformer = new DataCollectionTransformer(
|
||||
$this->dataClass,
|
||||
$type,
|
||||
$this->getInclusionTree(),
|
||||
$this->getExclusionTree(),
|
||||
$this->items,
|
||||
$this->through,
|
||||
$this->filter
|
||||
);
|
||||
|
||||
return $transformer->transform();
|
||||
}
|
||||
}
|
||||
23
app/DataTransferObjects/Support/PaginatedDataCollection.php
Normal file
23
app/DataTransferObjects/Support/PaginatedDataCollection.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\DataTransferObjects\Support;
|
||||
|
||||
use Spatie\LaravelData\Support\Wrapping\WrapExecutionType;
|
||||
|
||||
class PaginatedDataCollection extends \Spatie\LaravelData\PaginatedDataCollection
|
||||
{
|
||||
public function transform(bool $transformValues = true, WrapExecutionType $wrapExecutionType = WrapExecutionType::Disabled, bool $mapPropertyNames = true): array
|
||||
{
|
||||
$transformer = new DataCollectableTransformer(
|
||||
$this->dataClass,
|
||||
$transformValues,
|
||||
$wrapExecutionType,
|
||||
$mapPropertyNames,
|
||||
$this->getPartialTrees(),
|
||||
$this->items,
|
||||
$this->getWrap(),
|
||||
);
|
||||
|
||||
return $transformer->transform();
|
||||
}
|
||||
}
|
||||
@@ -3,10 +3,11 @@
|
||||
namespace App\DataTransferObjects\Support\Rules;
|
||||
|
||||
use Attribute;
|
||||
use Spatie\LaravelData\Attributes\Validation\ValidationAttribute;
|
||||
use Spatie\LaravelData\Support\Validation\ValidationPath;
|
||||
use Spatie\LaravelData\Attributes\Validation\CustomValidationAttribute;
|
||||
|
||||
#[Attribute(Attribute::TARGET_PROPERTY)]
|
||||
class CustomRule extends ValidationAttribute
|
||||
#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)]
|
||||
class CustomRule extends CustomValidationAttribute
|
||||
{
|
||||
protected array $rules = [];
|
||||
|
||||
@@ -15,10 +16,14 @@ class CustomRule extends ValidationAttribute
|
||||
$this->rules = $rules;
|
||||
}
|
||||
|
||||
public function getRules(): array
|
||||
/**
|
||||
* @return array<object|string>|object|string
|
||||
*/
|
||||
public function getRules(ValidationPath $path): array|object|string
|
||||
{
|
||||
return collect($this->rules)
|
||||
->map(fn (string $rule) => new $rule())
|
||||
->all();
|
||||
return array_map(
|
||||
fn (string $ruleClass) => new $ruleClass(),
|
||||
$this->rules
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,13 +2,15 @@
|
||||
|
||||
namespace App\DataTransferObjects\Support\Transformers;
|
||||
|
||||
use Illuminate\Support\Carbon;
|
||||
use Spatie\LaravelData\Support\DataProperty;
|
||||
use Spatie\LaravelData\Transformers\Transformer;
|
||||
|
||||
class CarbonTransformer implements Transformer
|
||||
{
|
||||
public function transform(DataProperty $property, mixed $value): mixed
|
||||
public function transform(DataProperty $property, mixed $value): string
|
||||
{
|
||||
/** @var Carbon $value */
|
||||
return $value->toISOString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,16 +19,11 @@ class UserData extends Data
|
||||
public function __construct(
|
||||
public ?int $id = null,
|
||||
public ?string $avatar = null,
|
||||
#[StringType,
|
||||
Max(255)]
|
||||
#[StringType, Max(255)]
|
||||
public ?string $name = null,
|
||||
#[StringType,
|
||||
Email,
|
||||
Max(255),
|
||||
Unique(User::class)]
|
||||
#[StringType, Email, Max(255), Unique(User::class)]
|
||||
public ?string $email = null,
|
||||
#[Exists(Package::class, 'id'),
|
||||
IntegerType]
|
||||
#[Exists(Package::class, 'id'), IntegerType]
|
||||
public ?int $package_id = null,
|
||||
#[StringType]
|
||||
public ?string $blocked = null,
|
||||
|
||||
@@ -2,18 +2,15 @@
|
||||
|
||||
namespace App\Filament\Pages;
|
||||
|
||||
use Filament\Forms;
|
||||
use App\Models\Server;
|
||||
use App\Models\Package;
|
||||
use Filament\Pages\Page;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Support\HtmlString;
|
||||
use Filament\Forms\Components\Grid;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\Toggle;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Forms\Components\FileUpload;
|
||||
use Filament\Forms\Components\Actions\Action;
|
||||
|
||||
class Settings extends Page
|
||||
@@ -40,15 +37,15 @@ class Settings extends Page
|
||||
'default_package' => setting('default_package'),
|
||||
'default_language' => setting('default_language'),
|
||||
'rotate_logs_after' => setting('rotate_logs_after'),
|
||||
'trial' => (bool) setting('trial'),
|
||||
'support' => (bool) setting('support'),
|
||||
'documentation' => (bool) setting('documentation'),
|
||||
'allow_registration' => (bool) setting('allow_registration'),
|
||||
'receive_email_on_server_creation' => (bool) setting('receive_email_on_server_creation'),
|
||||
'receive_email_on_site_creation' => (bool) setting('receive_email_on_site_creation'),
|
||||
'enable_api' => (bool) setting('enable_api'),
|
||||
'trial' => (bool)setting('trial'),
|
||||
'support' => (bool)setting('support'),
|
||||
'documentation' => (bool)setting('documentation'),
|
||||
'allow_registration' => (bool)setting('allow_registration'),
|
||||
'receive_email_on_server_creation' => (bool)setting('receive_email_on_server_creation'),
|
||||
'receive_email_on_site_creation' => (bool)setting('receive_email_on_site_creation'),
|
||||
'enable_api' => (bool)setting('enable_api'),
|
||||
'api_token' => setting('api_token'),
|
||||
'isolate_per_site_per_user' => (bool) setting('isolate_per_site_per_user'),
|
||||
'isolate_per_site_per_user' => (bool)setting('isolate_per_site_per_user'),
|
||||
'default_os' => setting('default_os', Server::OS_UBUNTU_22),
|
||||
]);
|
||||
}
|
||||
@@ -56,35 +53,34 @@ class Settings extends Page
|
||||
public function getFormSchema(): array
|
||||
{
|
||||
return [
|
||||
Grid::make(2)
|
||||
Forms\Components\Grid::make(2)
|
||||
->schema([
|
||||
|
||||
Grid::make(1)
|
||||
Forms\Components\Grid::make(2)
|
||||
->schema([
|
||||
TextInput::make('name')
|
||||
Forms\Components\TextInput::make('name')
|
||||
->label(__('Company name'))
|
||||
->required(),
|
||||
TextInput::make('email')
|
||||
Forms\Components\TextInput::make('email')
|
||||
->label(__('E-mail address'))
|
||||
->email(),
|
||||
TextInput::make('support_emails')
|
||||
Forms\Components\TextInput::make('support_emails')
|
||||
->label(__('Support email address'))
|
||||
->helperText('Separate by comma to allow more email addresses'),
|
||||
])
|
||||
->columnSpan(2),
|
||||
Select::make('default_package')
|
||||
->options(fn () => Package::orderBy('name')->get()->mapWithKeys(fn (Package $package) => [$package->id => $package->name]))
|
||||
Forms\Components\Select::make('default_package')
|
||||
->options(fn () => Package::orderBy('name')->pluck('name', 'id'))
|
||||
->label(__('Select default package'))
|
||||
->helperText(__('Select the default package a user should get when you create or they register')),
|
||||
Select::make('default_language')
|
||||
Forms\Components\Select::make('default_language')
|
||||
->options(collect(languages())->mapWithKeys(fn (string $language) => [$language => $language]))
|
||||
->label('Select default language')
|
||||
->helperText('Select the default language a user should get when you create or they register'),
|
||||
FileUpload::make('logo')
|
||||
Forms\Components\FileUpload::make('logo')
|
||||
->label(__('Logo'))
|
||||
->disk('logos')
|
||||
->columnSpan(2),
|
||||
Select::make('rotate_logs_after')
|
||||
Forms\Components\Select::make('rotate_logs_after')
|
||||
->label(__('This will rotate any logs older than selected, this helps cleanup your database'))
|
||||
->options([
|
||||
null => __("Don't rotate logs"),
|
||||
@@ -98,7 +94,7 @@ class Settings extends Page
|
||||
'years-4' => __('Older than 4 years'),
|
||||
])
|
||||
->columnSpan(1),
|
||||
Select::make('default_os')
|
||||
Forms\Components\Select::make('default_os')
|
||||
->label(__('Select the default OS that should be used when users create a server'))
|
||||
->default(Server::OS_UBUNTU_22)
|
||||
->options([
|
||||
@@ -107,30 +103,30 @@ class Settings extends Page
|
||||
Server::OS_UBUNTU_22 => __('Ubuntu 22'),
|
||||
])
|
||||
->columnSpan(1),
|
||||
Toggle::make('trial')
|
||||
Forms\Components\Toggle::make('trial')
|
||||
->label(__('Enable trial'))
|
||||
->helperText(__('This will allow you to have users with trials.')),
|
||||
Toggle::make('allow_registration')
|
||||
Forms\Components\Toggle::make('allow_registration')
|
||||
->label(__('Allow registration'))
|
||||
->helperText(__('This will allow your customers to make support requests to you.')),
|
||||
Toggle::make('support')
|
||||
->helperText(__('Allow customer registration')),
|
||||
Forms\Components\Toggle::make('support')
|
||||
->label(__('Enable support platform'))
|
||||
->helperText(__('This will allow your customers to make support requests to you.')),
|
||||
Toggle::make('documentation')
|
||||
Forms\Components\Toggle::make('documentation')
|
||||
->label(__('Enable documentation platform'))
|
||||
->helperText(__('This will allow you to create articles for your users to look at.')),
|
||||
Toggle::make('receive_email_on_server_creation')
|
||||
Forms\Components\Toggle::make('receive_email_on_server_creation')
|
||||
->label(__('Receive email when customers create server'))
|
||||
->helperText(__('This will send an email to all admins notifying them about a new server installation.')),
|
||||
Toggle::make('receive_email_on_site_creation')
|
||||
Forms\Components\Toggle::make('receive_email_on_site_creation')
|
||||
->label(__('Receive email when customers create site'))
|
||||
->helperText(__('This will send an email to all admins notifying them about a new site installation.')),
|
||||
Toggle::make('enable_api')
|
||||
Forms\Components\Toggle::make('enable_api')
|
||||
->label(__('Enable API'))
|
||||
->helperText(new HtmlString(__('This will allow you to interact with your system via the API. ') . '<a href="https://docs.ploi-core.io/core-api/introduction" target="_blank" class="text-primary-600">' . __('More information') . '</a>')),
|
||||
TextInput::make('api_token')
|
||||
->helperText(new HtmlString(__('This will allow you to interact with your system via the API. ') . '<a href="https://docs.ploi-core.io/304-core-api/737-introduction" target="_blank" class="text-primary-600">' . __('More information') . '</a>')),
|
||||
Forms\Components\TextInput::make('api_token')
|
||||
->label(__('API token'))
|
||||
->afterStateHydrated(function (?string $state, TextInput $component) {
|
||||
->afterStateHydrated(function (?string $state, Forms\Components\TextInput $component) {
|
||||
$state = filled($state) ? decrypt($state) : null;
|
||||
|
||||
$component->state($state);
|
||||
@@ -148,7 +144,7 @@ class Settings extends Page
|
||||
->tooltip('Generate'),
|
||||
])
|
||||
->suffixAction($generateAction),
|
||||
Toggle::make('isolate_per_site_per_user')
|
||||
Forms\Components\Toggle::make('isolate_per_site_per_user')
|
||||
->label(__('Enable site isolation per site & user'))
|
||||
->helperText(__('This will make sure each site created by one user is always isolated from another.')),
|
||||
]),
|
||||
@@ -178,11 +174,11 @@ class Settings extends Page
|
||||
|
||||
Notification::make()
|
||||
->success()
|
||||
->body(__('Settings saved.'))
|
||||
->title(__('Settings saved.'))
|
||||
->send();
|
||||
|
||||
if ($state['logo'] !== $oldLogo || $state['documentation'] !== $oldDocumentation || $state['support'] !== $oldSupport) {
|
||||
$this->redirectRoute('filament.pages.settings');
|
||||
$this->redirect(Settings::getUrl());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ use Laravel\Horizon\Contracts\MasterSupervisorRepository;
|
||||
|
||||
class System extends Page
|
||||
{
|
||||
protected static ?string $navigationIcon = 'heroicon-o-adjustments';
|
||||
protected static ?string $navigationIcon = 'heroicon-o-adjustments-vertical';
|
||||
|
||||
protected static string $view = 'filament.pages.system';
|
||||
|
||||
@@ -33,13 +33,13 @@ class System extends Page
|
||||
|
||||
Notification::make()
|
||||
->success()
|
||||
->body(__('Refreshed versions'))
|
||||
->title(__('Refreshed versions'))
|
||||
->send();
|
||||
}
|
||||
|
||||
public function getHorizonWorkerStatus(): bool
|
||||
{
|
||||
return rescue(fn () => (bool) app(MasterSupervisorRepository::class)->all(), false, false);
|
||||
return rescue(fn () => (bool)app(MasterSupervisorRepository::class)->all(), false, false);
|
||||
}
|
||||
|
||||
public function hasAvailableUpdate(): bool
|
||||
@@ -47,7 +47,7 @@ class System extends Page
|
||||
return app(VersionChecker::class)->getVersions()->isOutOfDate();
|
||||
}
|
||||
|
||||
protected static function getNavigationBadge(): ?string
|
||||
public static function getNavigationBadge(): ?string
|
||||
{
|
||||
$systemChecker = app(VersionChecker::class);
|
||||
|
||||
|
||||
@@ -2,12 +2,11 @@
|
||||
|
||||
namespace App\Filament\Pages;
|
||||
|
||||
use Filament\Forms;
|
||||
use Filament\Actions;
|
||||
use Filament\Pages\Page;
|
||||
use Illuminate\Support\Str;
|
||||
use Filament\Pages\Actions\Action;
|
||||
use Filament\Forms\Components\Toggle;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Forms\Components\MarkdownEditor;
|
||||
|
||||
class Terms extends Page
|
||||
{
|
||||
@@ -26,7 +25,7 @@ class Terms extends Page
|
||||
cache()->forget('core.settings');
|
||||
|
||||
$this->form->fill([
|
||||
'accept_terms_required' => (bool) setting('accept_terms_required'),
|
||||
'accept_terms_required' => (bool)setting('accept_terms_required'),
|
||||
'terms' => setting('terms'),
|
||||
'privacy' => setting('privacy'),
|
||||
]);
|
||||
@@ -35,20 +34,20 @@ class Terms extends Page
|
||||
protected function getFormSchema(): array
|
||||
{
|
||||
return [
|
||||
Toggle::make('accept_terms_required')
|
||||
Forms\Components\Toggle::make('accept_terms_required')
|
||||
->label(__(' Require users to accept terms of service on registration'))
|
||||
->helperText(__('This will require newly registered users to accept the terms of service.')),
|
||||
MarkdownEditor::make('terms')
|
||||
Forms\Components\MarkdownEditor::make('terms')
|
||||
->label(__('Content Terms Of Service')),
|
||||
MarkdownEditor::make('privacy')
|
||||
Forms\Components\MarkdownEditor::make('privacy')
|
||||
->label(__('Content Privacy Policy')),
|
||||
];
|
||||
}
|
||||
|
||||
protected function getActions(): array
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Action::make('load_terms_template')
|
||||
Actions\Action::make('load_terms_template')
|
||||
->label(__('Load Terms Of Service Template'))
|
||||
->action(function (self $livewire) {
|
||||
$template = Str::of(file_get_contents(storage_path('templates/terms-of-service.md')))
|
||||
@@ -67,7 +66,7 @@ class Terms extends Page
|
||||
|
||||
Notification::make()
|
||||
->success()
|
||||
->body(__('Loaded Terms Of Service Template'))
|
||||
->title(__('Loaded Terms Of Service Template'))
|
||||
->send();
|
||||
}),
|
||||
];
|
||||
@@ -88,7 +87,7 @@ class Terms extends Page
|
||||
|
||||
Notification::make()
|
||||
->success()
|
||||
->body(__('Terms saved.'))
|
||||
->title(__('Terms saved.'))
|
||||
->send();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,17 +2,14 @@
|
||||
|
||||
namespace App\Filament\Resources;
|
||||
|
||||
use Filament\Forms;
|
||||
use Filament\Tables;
|
||||
use App\Models\Alert;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Support\Str;
|
||||
use Filament\Resources\Form;
|
||||
use Filament\Resources\Table;
|
||||
use Filament\Resources\Resource;
|
||||
use Illuminate\Support\HtmlString;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Columns\BadgeColumn;
|
||||
use Filament\Forms\Components\DateTimePicker;
|
||||
use Filament\Forms\Components\MarkdownEditor;
|
||||
use App\Filament\Resources\AlertResource\Pages;
|
||||
|
||||
class AlertResource extends Resource
|
||||
@@ -31,11 +28,11 @@ class AlertResource extends Resource
|
||||
{
|
||||
return $form
|
||||
->schema([
|
||||
MarkdownEditor::make('message')
|
||||
Forms\Components\MarkdownEditor::make('message')
|
||||
->label(__('Content'))
|
||||
->columnSpan(2)
|
||||
->required(),
|
||||
Select::make('type')
|
||||
Forms\Components\Select::make('type')
|
||||
->label(__('Type'))
|
||||
->options([
|
||||
Alert::TYPE_INFO => __('Informational'),
|
||||
@@ -43,9 +40,9 @@ class AlertResource extends Resource
|
||||
Alert::TYPE_DANGER => __('Danger'),
|
||||
])
|
||||
->required(),
|
||||
DateTimePicker::make('expires_at')
|
||||
Forms\Components\DateTimePicker::make('expires_at')
|
||||
->label(__('Expires at'))
|
||||
->withoutSeconds(),
|
||||
->seconds(false),
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -53,24 +50,25 @@ class AlertResource extends Resource
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
TextColumn::make('message')
|
||||
Tables\Columns\TextColumn::make('message')
|
||||
->label(__('Content'))
|
||||
->formatStateUsing(fn (?string $state) => new HtmlString(Str::markdown($state))),
|
||||
BadgeColumn::make('type')
|
||||
Tables\Columns\TextColumn::make('type')
|
||||
->label(__('Type'))
|
||||
->enum([
|
||||
->badge()
|
||||
->formatStateUsing(fn (string $state) => match ($state) {
|
||||
Alert::TYPE_INFO => __('Informational'),
|
||||
Alert::TYPE_WARNING => __('Warning'),
|
||||
Alert::TYPE_DANGER => __('Danger'),
|
||||
])
|
||||
})
|
||||
->colors([
|
||||
'primary' => Alert::TYPE_INFO,
|
||||
'warning' => Alert::TYPE_WARNING,
|
||||
'danger' => Alert::TYPE_DANGER,
|
||||
]),
|
||||
TextColumn::make('expires_at')
|
||||
->label('Expires Date')
|
||||
->formatStateUsing(fn (?string $state) => filled($state) ? $state : '-'),
|
||||
Tables\Columns\TextColumn::make('expires_at')
|
||||
->label('Expires')
|
||||
->default('-'),
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace App\Filament\Resources\AlertResource\Pages;
|
||||
|
||||
use Filament\Pages\Actions\DeleteAction;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
use App\Filament\Resources\AlertResource;
|
||||
|
||||
@@ -10,10 +10,10 @@ class EditAlert extends EditRecord
|
||||
{
|
||||
protected static string $resource = AlertResource::class;
|
||||
|
||||
protected function getActions(): array
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
DeleteAction::make(),
|
||||
Actions\DeleteAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,18 +2,21 @@
|
||||
|
||||
namespace App\Filament\Resources\AlertResource\Pages;
|
||||
|
||||
use Filament\Pages\Actions\CreateAction;
|
||||
use Filament\Actions;
|
||||
use App\Filament\Resources\AlertResource;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
use Illuminate\Contracts\Support\Htmlable;
|
||||
|
||||
class ListAlerts extends ListRecords
|
||||
{
|
||||
protected static string $resource = AlertResource::class;
|
||||
|
||||
protected function getActions(): array
|
||||
protected ?string $subheading = 'Alerts are meant to inform your users about things that are going on. For example server migrations, pricing changes. They will display as top-banner inside the panel.';
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
CreateAction::make(),
|
||||
Actions\CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,19 +4,19 @@ namespace App\Filament\Resources;
|
||||
|
||||
use Filament\Forms;
|
||||
use Filament\Tables;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Tables\Table;
|
||||
use App\Models\Certificate;
|
||||
use Filament\Resources\Form;
|
||||
use Filament\Resources\Table;
|
||||
use Filament\Resources\Resource;
|
||||
use Illuminate\Support\HtmlString;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use App\Filament\Resources\CertificateResource\Pages;
|
||||
use Illuminate\Support\HtmlString;
|
||||
|
||||
class CertificateResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Certificate::class;
|
||||
|
||||
protected static ?string $navigationIcon = 'heroicon-o-annotation';
|
||||
protected static ?string $navigationIcon = 'heroicon-o-chat-bubble-bottom-center-text';
|
||||
|
||||
protected static ?string $navigationGroup = 'Site management';
|
||||
|
||||
@@ -28,15 +28,12 @@ class CertificateResource extends Resource
|
||||
->schema([
|
||||
Forms\Components\TextInput::make('site.name'),
|
||||
Forms\Components\TextInput::make('server_id'),
|
||||
Forms\Components\TextInput::make('status')
|
||||
->maxLength(255),
|
||||
Forms\Components\TextInput::make('status'),
|
||||
Forms\Components\TextInput::make('ploi_id'),
|
||||
Forms\Components\TextInput::make('domain')
|
||||
->maxLength(255),
|
||||
Forms\Components\TextInput::make('domain'),
|
||||
Forms\Components\Textarea::make('certificate'),
|
||||
Forms\Components\Textarea::make('private'),
|
||||
Forms\Components\TextInput::make('type')
|
||||
->maxLength(255),
|
||||
Forms\Components\TextInput::make('type'),
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -52,11 +49,12 @@ class CertificateResource extends Resource
|
||||
->label(__('Main domain')),
|
||||
Tables\Columns\TextColumn::make('type')
|
||||
->label('Type'),
|
||||
Tables\Columns\BadgeColumn::make('status')
|
||||
->enum([
|
||||
Tables\Columns\TextColumn::make('status')
|
||||
->badge()
|
||||
->formatStateUsing(fn (string $state) => match ($state) {
|
||||
Certificate::STATUS_BUSY => __('Busy'),
|
||||
Certificate::STATUS_ACTIVE => __('Active'),
|
||||
])
|
||||
})
|
||||
->colors([
|
||||
'warning' => Certificate::STATUS_BUSY,
|
||||
'success' => Certificate::STATUS_ACTIVE,
|
||||
@@ -81,6 +79,7 @@ class CertificateResource extends Resource
|
||||
])
|
||||
->actions([
|
||||
Tables\Actions\EditAction::make(),
|
||||
Tables\Actions\DeleteAction::make(),
|
||||
])
|
||||
->bulkActions([
|
||||
Tables\Actions\DeleteBulkAction::make(),
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace App\Filament\Resources\CertificateResource\Pages;
|
||||
|
||||
use Filament\Pages\Actions;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
use App\Filament\Resources\CertificateResource;
|
||||
|
||||
@@ -10,7 +10,7 @@ class ListCertificates extends ListRecords
|
||||
{
|
||||
protected static string $resource = CertificateResource::class;
|
||||
|
||||
protected function getActions(): array
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\CreateAction::make(),
|
||||
|
||||
@@ -4,8 +4,8 @@ namespace App\Filament\Resources;
|
||||
|
||||
use Filament\Tables;
|
||||
use App\Models\Cronjob;
|
||||
use Filament\Resources\Form;
|
||||
use Filament\Resources\Table;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Tables\Table;
|
||||
use Filament\Resources\Resource;
|
||||
use App\Filament\Resources\CronjobResource\Pages;
|
||||
|
||||
@@ -34,11 +34,12 @@ class CronjobResource extends Resource
|
||||
Tables\Columns\TextColumn::make('site.domain')
|
||||
->searchable()
|
||||
->label(__('Site')),
|
||||
Tables\Columns\BadgeColumn::make('status')
|
||||
->enum([
|
||||
Tables\Columns\TextColumn::make('status')
|
||||
->badge()
|
||||
->formatStateUsing(fn (string $state) => match ($state) {
|
||||
Cronjob::STATUS_BUSY => __('Busy'),
|
||||
Cronjob::STATUS_ACTIVE => __('Active'),
|
||||
])
|
||||
})
|
||||
->colors([
|
||||
'warning' => Cronjob::STATUS_BUSY,
|
||||
'success' => Cronjob::STATUS_ACTIVE,
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace App\Filament\Resources\CronjobResource\Pages;
|
||||
|
||||
use Filament\Pages\Actions;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
use App\Filament\Resources\CronjobResource;
|
||||
|
||||
@@ -10,7 +10,7 @@ class EditCronjob extends EditRecord
|
||||
{
|
||||
protected static string $resource = CronjobResource::class;
|
||||
|
||||
protected function getActions(): array
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\DeleteAction::make(),
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace App\Filament\Resources\CronjobResource\Pages;
|
||||
|
||||
use Filament\Pages\Actions;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
use App\Filament\Resources\CronjobResource;
|
||||
|
||||
@@ -10,7 +10,7 @@ class ListCronjobs extends ListRecords
|
||||
{
|
||||
protected static string $resource = CronjobResource::class;
|
||||
|
||||
protected function getActions(): array
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\CreateAction::make(),
|
||||
|
||||
@@ -4,8 +4,8 @@ namespace App\Filament\Resources;
|
||||
|
||||
use Filament\Tables;
|
||||
use App\Models\Database;
|
||||
use Filament\Resources\Form;
|
||||
use Filament\Resources\Table;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Tables\Table;
|
||||
use Filament\Resources\Resource;
|
||||
use App\Filament\Resources\DatabaseResource\Pages;
|
||||
|
||||
@@ -13,7 +13,7 @@ class DatabaseResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Database::class;
|
||||
|
||||
protected static ?string $navigationIcon = 'heroicon-o-database';
|
||||
protected static ?string $navigationIcon = 'heroicon-o-circle-stack';
|
||||
|
||||
protected static ?string $navigationGroup = 'Site management';
|
||||
|
||||
@@ -40,17 +40,17 @@ class DatabaseResource extends Resource
|
||||
Tables\Columns\TextColumn::make('site.domain')
|
||||
->label(__('Site'))
|
||||
->searchable(),
|
||||
Tables\Columns\BadgeColumn::make('status')
|
||||
->enum([
|
||||
Tables\Columns\TextColumn::make('status')
|
||||
->badge()
|
||||
->formatStateUsing(fn (string $state) => match ($state) {
|
||||
Database::STATUS_BUSY => __('Busy'),
|
||||
Database::STATUS_ACTIVE => __('Active'),
|
||||
])
|
||||
})
|
||||
->colors([
|
||||
'warning' => Database::STATUS_BUSY,
|
||||
'success' => Database::STATUS_ACTIVE,
|
||||
])
|
||||
->label(__('Status')),
|
||||
|
||||
Tables\Columns\TextColumn::make('created_at')
|
||||
->label(__('Date'))
|
||||
->sortable()
|
||||
|
||||
@@ -56,7 +56,7 @@ class EditDatabase extends Page
|
||||
$this->recentlyUpdatedPassword = $data->new_password;
|
||||
|
||||
Notification::make()
|
||||
->body(__('Successfully reset database password.'))
|
||||
->title(__('Successfully reset database password.'))
|
||||
->success()
|
||||
->send();
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace App\Filament\Resources\DatabaseResource\Pages;
|
||||
|
||||
use Filament\Pages\Actions;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
use App\Filament\Resources\DatabaseResource;
|
||||
|
||||
@@ -10,7 +10,7 @@ class ListDatabases extends ListRecords
|
||||
{
|
||||
protected static string $resource = DatabaseResource::class;
|
||||
|
||||
protected function getActions(): array
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\CreateAction::make(),
|
||||
|
||||
@@ -2,17 +2,16 @@
|
||||
|
||||
namespace App\Filament\Resources;
|
||||
|
||||
use Filament\Forms;
|
||||
use Filament\Tables;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Support\Str;
|
||||
use Filament\Resources\Form;
|
||||
use Filament\Resources\Table;
|
||||
use Filament\Resources\Resource;
|
||||
use Illuminate\Support\HtmlString;
|
||||
use App\Models\DocumentationCategory;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Components\MarkdownEditor;
|
||||
use App\Filament\Resources\DocumentationCategoryResource\Pages;
|
||||
use App\Filament\Resources\DocumentationCategoryResource\RelationManagers\DocumentationItemsRelationManager;
|
||||
use App\Filament\Resources\DocumentationCategoryResource\RelationManagers;
|
||||
|
||||
class DocumentationCategoryResource extends Resource
|
||||
{
|
||||
@@ -28,21 +27,21 @@ class DocumentationCategoryResource extends Resource
|
||||
|
||||
protected static ?string $label = 'Category';
|
||||
|
||||
protected static function shouldRegisterNavigation(): bool
|
||||
public static function shouldRegisterNavigation(): bool
|
||||
{
|
||||
return (bool) setting('documentation');
|
||||
return (bool)setting('documentation');
|
||||
}
|
||||
|
||||
public static function form(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
->schema([
|
||||
TextInput::make('title')
|
||||
Forms\Components\TextInput::make('title')
|
||||
->label(__('Title'))
|
||||
->unique(table: DocumentationCategory::class, column: 'title', ignoreRecord: true)
|
||||
->required()
|
||||
->columnSpan(2),
|
||||
MarkdownEditor::make('description')
|
||||
Forms\Components\MarkdownEditor::make('description')
|
||||
->label(__('Description'))
|
||||
->required()
|
||||
->columnSpan(2),
|
||||
@@ -53,11 +52,11 @@ class DocumentationCategoryResource extends Resource
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
TextColumn::make('title')
|
||||
Tables\Columns\TextColumn::make('title')
|
||||
->searchable()
|
||||
->sortable()
|
||||
->label(__('Title')),
|
||||
TextColumn::make('description')
|
||||
Tables\Columns\TextColumn::make('description')
|
||||
->label(__('Description'))
|
||||
->formatStateUsing(fn (string $state) => new HtmlString(Str::markdown($state))),
|
||||
]);
|
||||
@@ -66,7 +65,7 @@ class DocumentationCategoryResource extends Resource
|
||||
public static function getRelations(): array
|
||||
{
|
||||
return [
|
||||
DocumentationItemsRelationManager::class,
|
||||
RelationManagers\DocumentationItemsRelationManager::class,
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace App\Filament\Resources\DocumentationCategoryResource\Pages;
|
||||
|
||||
use Filament\Pages\Actions\DeleteAction;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
use App\Filament\Resources\DocumentationCategoryResource;
|
||||
|
||||
@@ -10,10 +10,10 @@ class EditDocumentationCategory extends EditRecord
|
||||
{
|
||||
protected static string $resource = DocumentationCategoryResource::class;
|
||||
|
||||
protected function getActions(): array
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
DeleteAction::make(),
|
||||
Actions\DeleteAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace App\Filament\Resources\DocumentationCategoryResource\Pages;
|
||||
|
||||
use Filament\Pages\Actions\CreateAction;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
use App\Filament\Resources\DocumentationCategoryResource;
|
||||
|
||||
@@ -10,10 +10,10 @@ class ListDocumentationCategories extends ListRecords
|
||||
{
|
||||
protected static string $resource = DocumentationCategoryResource::class;
|
||||
|
||||
protected function getActions(): array
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
CreateAction::make(),
|
||||
Actions\CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,8 +4,8 @@ namespace App\Filament\Resources\DocumentationCategoryResource\RelationManagers;
|
||||
|
||||
use Filament\Forms;
|
||||
use Filament\Tables;
|
||||
use Filament\Resources\Form;
|
||||
use Filament\Resources\Table;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Tables\Table;
|
||||
use Filament\Resources\RelationManagers\RelationManager;
|
||||
|
||||
class DocumentationItemsRelationManager extends RelationManager
|
||||
@@ -18,7 +18,7 @@ class DocumentationItemsRelationManager extends RelationManager
|
||||
|
||||
protected static ?string $pluralLabel = 'Articles';
|
||||
|
||||
public static function form(Form $form): Form
|
||||
public function form(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
->schema([
|
||||
@@ -28,7 +28,7 @@ class DocumentationItemsRelationManager extends RelationManager
|
||||
]);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
public function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
|
||||
@@ -2,14 +2,12 @@
|
||||
|
||||
namespace App\Filament\Resources;
|
||||
|
||||
use Filament\Resources\Form;
|
||||
use Filament\Resources\Table;
|
||||
use Filament\Forms;
|
||||
use Filament\Tables;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Tables\Table;
|
||||
use Filament\Resources\Resource;
|
||||
use App\Models\DocumentationItem;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Components\MarkdownEditor;
|
||||
use App\Filament\Resources\DocumentationItemResource\Pages;
|
||||
|
||||
class DocumentationItemResource extends Resource
|
||||
@@ -26,23 +24,23 @@ class DocumentationItemResource extends Resource
|
||||
|
||||
protected static ?string $label = 'Article';
|
||||
|
||||
protected static function shouldRegisterNavigation(): bool
|
||||
public static function shouldRegisterNavigation(): bool
|
||||
{
|
||||
return (bool) setting('documentation');
|
||||
return (bool)setting('documentation');
|
||||
}
|
||||
|
||||
public static function form(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
->schema([
|
||||
TextInput::make('title')
|
||||
Forms\Components\TextInput::make('title')
|
||||
->label(__('Title'))
|
||||
->required(),
|
||||
Select::make('documentation_category_id')
|
||||
Forms\Components\Select::make('documentation_category_id')
|
||||
->relationship('category', 'title')
|
||||
->searchable()
|
||||
->preload(),
|
||||
MarkdownEditor::make('content')
|
||||
Forms\Components\MarkdownEditor::make('content')
|
||||
->label(__('Content'))
|
||||
->required()
|
||||
->columnSpan(2),
|
||||
@@ -53,11 +51,10 @@ class DocumentationItemResource extends Resource
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
TextColumn::make('title')
|
||||
Tables\Columns\TextColumn::make('title')
|
||||
->searchable()
|
||||
->sortable(),
|
||||
|
||||
TextColumn::make('category.title')
|
||||
Tables\Columns\TextColumn::make('category.title')
|
||||
->searchable()
|
||||
->sortable(),
|
||||
]);
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace App\Filament\Resources\DocumentationItemResource\Pages;
|
||||
|
||||
use Filament\Pages\Actions\DeleteAction;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
use App\Filament\Resources\DocumentationItemResource;
|
||||
|
||||
@@ -10,10 +10,10 @@ class EditDocumentationItem extends EditRecord
|
||||
{
|
||||
protected static string $resource = DocumentationItemResource::class;
|
||||
|
||||
protected function getActions(): array
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
DeleteAction::make(),
|
||||
Actions\DeleteAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace App\Filament\Resources\DocumentationItemResource\Pages;
|
||||
|
||||
use Filament\Pages\Actions\CreateAction;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
use App\Filament\Resources\DocumentationItemResource;
|
||||
|
||||
@@ -10,10 +10,10 @@ class ListDocumentationItems extends ListRecords
|
||||
{
|
||||
protected static string $resource = DocumentationItemResource::class;
|
||||
|
||||
protected function getActions(): array
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
CreateAction::make(),
|
||||
Actions\CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,25 +2,24 @@
|
||||
|
||||
namespace App\Filament\Resources;
|
||||
|
||||
use Filament\Tables;
|
||||
use App\Models\Package;
|
||||
use Filament\Resources\Form;
|
||||
use Filament\Resources\Table;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Forms\Components\Grid;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\Section;
|
||||
use Filament\Forms\Components\Checkbox;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Components\CheckboxList;
|
||||
use App\Filament\Resources\PackageResource\Pages;
|
||||
use App\Filament\Resources\PackageResource\RelationManagers;
|
||||
use App\Models\Package;
|
||||
use App\Models\Provider;
|
||||
use App\Models\ProviderPlan;
|
||||
use Filament\Forms;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Support\HtmlString;
|
||||
|
||||
class PackageResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Package::class;
|
||||
|
||||
protected static ?string $navigationIcon = 'heroicon-o-color-swatch';
|
||||
protected static ?string $navigationIcon = 'heroicon-o-swatch';
|
||||
|
||||
protected static ?int $navigationSort = 3;
|
||||
|
||||
@@ -28,33 +27,31 @@ class PackageResource extends Resource
|
||||
{
|
||||
return $form
|
||||
->schema([
|
||||
TextInput::make('name')
|
||||
Forms\Components\TextInput::make('name')
|
||||
->label(__('Name'))
|
||||
->required()
|
||||
->columnSpan(2),
|
||||
TextInput::make('maximum_sites')
|
||||
Forms\Components\TextInput::make('maximum_sites')
|
||||
->helperText(__('Set to 0 for unlimited'))
|
||||
->integer()
|
||||
->required(),
|
||||
TextInput::make('maximum_servers')
|
||||
Forms\Components\TextInput::make('maximum_servers')
|
||||
->helperText(__('Set to 0 for unlimited'))
|
||||
->integer()
|
||||
->required(),
|
||||
TextInput::make('stripe_plan_id')
|
||||
->helperText(__('Enter the pricing ID from Stripe here') . ' - <a href="https://docs.ploi-core.io/digging-deeper/using-stripe" target="ploi-docs-stripe" class="text-primary-500">How does this work?</a>')
|
||||
Forms\Components\TextInput::make('stripe_plan_id')
|
||||
->helperText(new HtmlString(__('Enter the pricing ID from Stripe here') . ' - <a href="https://docs.ploi-core.io/263-digging-deeper/743-using-stripe" target="ploi-docs-stripe" class="text-primary-500">How does this work?</a>'))
|
||||
->label(__('Stripe ID'))
|
||||
->columnSpan(2),
|
||||
TextInput::make('price_monthly')
|
||||
->numeric()
|
||||
Forms\Components\TextInput::make('price_monthly')
|
||||
->label(__('Monthly price'))
|
||||
->helperText(__('Fill this in if you want it to be monthly payments'))
|
||||
->required(),
|
||||
TextInput::make('price_yearly')
|
||||
->numeric()
|
||||
Forms\Components\TextInput::make('price_yearly')
|
||||
->label(__('Yearly price'))
|
||||
->helperText(__('Fill this in if you want it to be yearly payments'))
|
||||
->required(),
|
||||
Select::make('currency')
|
||||
Forms\Components\Select::make('currency')
|
||||
->label(__('Currency'))
|
||||
->options([
|
||||
'usd' => 'USD $',
|
||||
@@ -66,46 +63,135 @@ class PackageResource extends Resource
|
||||
'inr' => 'INR (Indian ₹ rupee)',
|
||||
'thb' => 'THB (Thai Baht)',
|
||||
'brl' => 'BRL R$ (Brazilian Real)',
|
||||
'nz' => 'NZD $ (New Zealand Dollar)',
|
||||
])
|
||||
->required(),
|
||||
Grid::make()
|
||||
Forms\Components\Grid::make()
|
||||
->schema([
|
||||
Section::make(__('Server permissions'))
|
||||
Forms\Components\Section::make(__('Server permissions'))
|
||||
->icon(ServerResource::getNavigationIcon())
|
||||
->schema([
|
||||
Checkbox::make('server_permissions.create')
|
||||
Forms\Components\Checkbox::make('server_permissions.create')
|
||||
->reactive()
|
||||
->label('Allow server creation')
|
||||
->helperText('This will allow users to create servers'),
|
||||
Checkbox::make('server_permissions.update')
|
||||
Forms\Components\Checkbox::make('server_permissions.update')
|
||||
->label('Allow server updates')
|
||||
->helperText('This will allow users to update servers'),
|
||||
Checkbox::make('server_permissions.delete')
|
||||
Forms\Components\Checkbox::make('server_permissions.delete')
|
||||
->label('Allow server deletion')
|
||||
->helperText('This will allow users to delete servers'),
|
||||
])
|
||||
->columnSpan(1),
|
||||
Section::make(__('Site permissions'))
|
||||
Forms\Components\Section::make(__('Site permissions'))
|
||||
->icon(SiteResource::getNavigationIcon())
|
||||
->schema([
|
||||
Checkbox::make('site_permissions.create')
|
||||
Forms\Components\Checkbox::make('site_permissions.create')
|
||||
->label('Allow site creation')
|
||||
->helperText('This will allow users to create sites'),
|
||||
Checkbox::make('site_permissions.update')
|
||||
Forms\Components\Checkbox::make('site_permissions.update')
|
||||
->label('Allow site updates')
|
||||
->helperText('This will allow users to update sites'),
|
||||
Checkbox::make('site_permissions.delete')
|
||||
Forms\Components\Checkbox::make('site_permissions.delete')
|
||||
->label('Allow site deletion')
|
||||
->helperText('This will allow users to delete sites'),
|
||||
])
|
||||
->columnSpan(1),
|
||||
]),
|
||||
|
||||
Grid::make()
|
||||
Forms\Components\Grid::make()
|
||||
->schema([
|
||||
Section::make(__('Available server providers'))
|
||||
Forms\Components\Section::make(__('Available server providers'))
|
||||
->description(__('These server providers will be available for users that are attached to this package.'))
|
||||
->icon(ProviderResource::getNavigationIcon())
|
||||
->schema([
|
||||
CheckboxList::make('providers')
|
||||
Forms\Components\CheckboxList::make('providers')
|
||||
->relationship('providers', 'name')
|
||||
->reactive(),
|
||||
Forms\Components\Grid::make(1)
|
||||
->schema([
|
||||
Forms\Components\Actions::make([
|
||||
Forms\Components\Actions\Action::make('manage_provider_plans')
|
||||
->label(__('Manage provider plans'))
|
||||
->icon('heroicon-o-adjustments-horizontal')
|
||||
->form(function (Package $record) {
|
||||
return $record->providers->sortBy('name')->map(function (Provider $provider) {
|
||||
return Forms\Components\Section::make($provider->label)
|
||||
->description(__('Select the plans that should be available for this provider on this package.'))
|
||||
->icon(ProviderResource::getNavigationIcon())
|
||||
->statePath($provider->id)
|
||||
->schema([
|
||||
Forms\Components\Toggle::make('select_specific_provider_plans')
|
||||
->label(__('Select subset'))
|
||||
->helperText(__('Check this box if you want to limit the provider plans available on this package.'))
|
||||
->default(false)
|
||||
->reactive()
|
||||
->afterStateUpdated(function (Forms\Components\Toggle $component, Forms\Set $set) use ($provider) {
|
||||
$set(
|
||||
path: "provider_plans",
|
||||
state: $component->getState() ? $provider->plans->pluck('id') : [],
|
||||
);
|
||||
}),
|
||||
Forms\Components\CheckboxList::make("provider_plans")
|
||||
->label(__('Select plans'))
|
||||
->options(fn() => $provider->plans->mapWithKeys(fn(ProviderPlan $providerPlan) => [$providerPlan->id => $providerPlan->label ?? $providerPlan->plan_id])->all())
|
||||
->visible(fn(Forms\Get $get) => $get('select_specific_provider_plans'))
|
||||
->reactive()
|
||||
->bulkToggleable()
|
||||
->columns(2)
|
||||
])
|
||||
->collapsible();
|
||||
})->all();
|
||||
})
|
||||
->fillForm(function (Package $record) {
|
||||
return $record->providers->mapWithKeys(function (Provider $provider) use ($record) {
|
||||
$providerPlanIds = $record->providerPlans()->whereBelongsTo($provider)->pluck('provider_plans.id');
|
||||
|
||||
return [$provider->id => [
|
||||
'select_specific_provider_plans' => $providerPlanIds->isNotEmpty(),
|
||||
'provider_plans' => $providerPlanIds->all(),
|
||||
]];
|
||||
})->all();
|
||||
})
|
||||
->action(function (Package $record, array $data) {
|
||||
$providerPlanIds = collect($data)
|
||||
// If `select_specific_provider_plans`, all provider plans are available. It could be that this
|
||||
// option was deselected, and that we have some left over provider plans in the field that
|
||||
// is now hidden. We will not include theSE IDs so that they ARE detached automatically.
|
||||
->where('select_specific_provider_plans', true)
|
||||
->pluck('provider_plans')
|
||||
->flatten();
|
||||
|
||||
// Detaches provider plans not specifically selected.
|
||||
$record->providerPlans()->sync($providerPlanIds);
|
||||
|
||||
Notification::make()
|
||||
->title(__('Provider plans saved'))
|
||||
->success()
|
||||
->send();
|
||||
})
|
||||
->modalSubmitActionLabel(__('Save'))
|
||||
->color('gray')
|
||||
->disabled(function (Package $record, Forms\Get $get) {
|
||||
$providers = collect($get('providers'))
|
||||
->map(fn(string $id): int => (int)$id)
|
||||
->sort();
|
||||
|
||||
return $record->providers->pluck('id')->map(fn(string $id): int => (int)$id)->sort()->toArray() !== $providers->all();
|
||||
})
|
||||
]),
|
||||
Forms\Components\Placeholder::make('save_warning')
|
||||
->content(__('You\'ve changed the available server providers. Please save your changes before you can manage the provider plans.'))
|
||||
->visible(function (Package $record, Forms\Get $get) {
|
||||
$providers = collect($get('providers'))
|
||||
->map(fn(string $id): int => (int)$id)
|
||||
->sort();
|
||||
|
||||
return $record->providers->pluck('id')->map(fn(string $id): int => (int)$id)->sort()->toArray() !== $providers->all();
|
||||
})
|
||||
->hiddenLabel(),
|
||||
])
|
||||
->hiddenOn('create'),
|
||||
])
|
||||
->columnSpan(1)
|
||||
])
|
||||
@@ -119,7 +205,9 @@ class PackageResource extends Resource
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('id')->label('ID')->searchable(),
|
||||
Tables\Columns\TextColumn::make('id')
|
||||
->label('ID')
|
||||
->searchable(),
|
||||
Tables\Columns\TextColumn::make('name')
|
||||
->label(__('Name'))
|
||||
->description(function (Package $record) {
|
||||
@@ -130,10 +218,10 @@ class PackageResource extends Resource
|
||||
return "Attached to stripe - {$record->price_monthly} {$record->currency}";
|
||||
}),
|
||||
Tables\Columns\TextColumn::make('maximum_sites')
|
||||
->formatStateUsing(fn (int $state) => $state === 0 ? __('Unlimited') : $state)
|
||||
->formatStateUsing(fn(int $state) => $state === 0 ? __('Unlimited') : $state)
|
||||
->label(__('Maximum sites')),
|
||||
Tables\Columns\TextColumn::make('maximum_servers')
|
||||
->formatStateUsing(fn (int $state) => $state === 0 ? __('Unlimited') : $state)
|
||||
->formatStateUsing(fn(int $state) => $state === 0 ? __('Unlimited') : $state)
|
||||
->label(__('Maximum servers')),
|
||||
Tables\Columns\TextColumn::make('users_count')
|
||||
->counts('users'),
|
||||
@@ -143,6 +231,7 @@ class PackageResource extends Resource
|
||||
])
|
||||
->actions([
|
||||
Tables\Actions\EditAction::make(),
|
||||
Tables\Actions\DeleteAction::make(),
|
||||
])
|
||||
->bulkActions([
|
||||
Tables\Actions\DeleteBulkAction::make(),
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace App\Filament\Resources\PackageResource\Pages;
|
||||
|
||||
use Filament\Pages\Actions;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
use App\Filament\Resources\PackageResource;
|
||||
|
||||
@@ -10,10 +10,17 @@ class EditPackage extends EditRecord
|
||||
{
|
||||
protected static string $resource = PackageResource::class;
|
||||
|
||||
protected function getActions(): array
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\DeleteAction::make(),
|
||||
];
|
||||
}
|
||||
|
||||
public function afterSave(): void
|
||||
{
|
||||
// Necessary to refresh, in order to load the updated saved relationships and
|
||||
// correctly show or hide the "manage provider plans" warning placeholder.
|
||||
$this->getRecord()->refresh();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace App\Filament\Resources\PackageResource\Pages;
|
||||
|
||||
use Filament\Pages\Actions;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
use App\Filament\Resources\PackageResource;
|
||||
|
||||
@@ -10,7 +10,7 @@ class ListPackages extends ListRecords
|
||||
{
|
||||
protected static string $resource = PackageResource::class;
|
||||
|
||||
protected function getActions(): array
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\CreateAction::make(),
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
namespace App\Filament\Resources\PackageResource\RelationManagers;
|
||||
|
||||
use App\Models\User;
|
||||
use Filament\Resources\Form;
|
||||
use Filament\Resources\Table;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Tables\Table;
|
||||
use Filament\Tables\Actions\Action;
|
||||
use Filament\Forms\Components\Select;
|
||||
use App\Filament\Resources\UserResource;
|
||||
@@ -16,15 +16,16 @@ class UsersRelationManager extends RelationManager
|
||||
|
||||
protected static ?string $recordTitleAttribute = 'name';
|
||||
|
||||
public static function form(Form $form): Form
|
||||
public function form(Form $form): Form
|
||||
{
|
||||
return UserResource::form($form);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
public function table(Table $table): Table
|
||||
{
|
||||
return UserResource::table($table)
|
||||
->appendHeaderActions([
|
||||
->headerActions([
|
||||
...$table->getHeaderActions(),
|
||||
Action::make('add_user')
|
||||
->label(__('Add user'))
|
||||
->form(fn (self $livewire) => [
|
||||
|
||||
@@ -2,13 +2,13 @@
|
||||
|
||||
namespace App\Filament\Resources;
|
||||
|
||||
use Filament\Forms;
|
||||
use Filament\Tables;
|
||||
use App\Models\Provider;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Tables\Table;
|
||||
use App\Models\ProviderPlan;
|
||||
use Filament\Resources\Form;
|
||||
use Filament\Resources\Table;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use App\Filament\Resources\ProviderPlanResource\Pages;
|
||||
|
||||
class ProviderPlanResource extends Resource
|
||||
@@ -25,7 +25,7 @@ class ProviderPlanResource extends Resource
|
||||
{
|
||||
return $form
|
||||
->schema([
|
||||
TextInput::make('label'),
|
||||
Forms\Components\TextInput::make('label'),
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -33,7 +33,9 @@ class ProviderPlanResource extends Resource
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('id')->label('ID')->searchable(),
|
||||
Tables\Columns\TextColumn::make('id')
|
||||
->label('ID')
|
||||
->searchable(),
|
||||
Tables\Columns\TextColumn::make('provider.name')
|
||||
->label(__('Provider'))
|
||||
->searchable(),
|
||||
|
||||
@@ -9,7 +9,7 @@ class ListProviderPlans extends ListRecords
|
||||
{
|
||||
protected static string $resource = ProviderPlanResource::class;
|
||||
|
||||
protected function getActions(): array
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
|
||||
@@ -4,8 +4,8 @@ namespace App\Filament\Resources;
|
||||
|
||||
use Filament\Tables;
|
||||
use App\Models\Provider;
|
||||
use Filament\Resources\Form;
|
||||
use Filament\Resources\Table;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Tables\Table;
|
||||
use App\Models\ProviderRegion;
|
||||
use Filament\Resources\Resource;
|
||||
use App\Filament\Resources\ProviderRegionResource\Pages;
|
||||
@@ -14,7 +14,7 @@ class ProviderRegionResource extends Resource
|
||||
{
|
||||
protected static ?string $model = ProviderRegion::class;
|
||||
|
||||
protected static ?string $navigationIcon = 'heroicon-o-globe';
|
||||
protected static ?string $navigationIcon = 'heroicon-o-globe-americas';
|
||||
|
||||
protected static ?string $navigationGroup = 'Providers';
|
||||
|
||||
@@ -32,7 +32,9 @@ class ProviderRegionResource extends Resource
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('id')->label('ID')->searchable(),
|
||||
Tables\Columns\TextColumn::make('id')
|
||||
->label('ID')
|
||||
->searchable(),
|
||||
Tables\Columns\TextColumn::make('provider.name')
|
||||
->label(__('Provider'))
|
||||
->searchable(),
|
||||
@@ -46,7 +48,7 @@ class ProviderRegionResource extends Resource
|
||||
->filters([
|
||||
Tables\Filters\SelectFilter::make('provider_id')
|
||||
->label(__('Provider'))
|
||||
->options(fn () => Provider::orderBy('name')->get()->mapWithKeys(fn (Provider $provider) => [$provider->id => $provider->name])),
|
||||
->options(fn () => Provider::orderBy('name')->pluck('name', 'id'))
|
||||
])
|
||||
->actions([
|
||||
//
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace App\Filament\Resources\ProviderRegionResource\Pages;
|
||||
|
||||
use Filament\Pages\Actions;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
use App\Filament\Resources\ProviderRegionResource;
|
||||
|
||||
@@ -10,7 +10,7 @@ class ListProviderRegions extends ListRecords
|
||||
{
|
||||
protected static string $resource = ProviderRegionResource::class;
|
||||
|
||||
protected function getActions(): array
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\CreateAction::make(),
|
||||
|
||||
@@ -5,9 +5,9 @@ namespace App\Filament\Resources;
|
||||
use Filament\Forms;
|
||||
use Filament\Tables;
|
||||
use App\Models\Provider;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Tables\Table;
|
||||
use App\Models\ProviderPlan;
|
||||
use Filament\Resources\Form;
|
||||
use Filament\Resources\Table;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Notifications\Notification;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
@@ -19,7 +19,7 @@ class ProviderResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Provider::class;
|
||||
|
||||
protected static ?string $navigationIcon = 'heroicon-o-cloud-upload';
|
||||
protected static ?string $navigationIcon = 'heroicon-o-cloud-arrow-up';
|
||||
|
||||
protected static ?string $navigationGroup = 'Providers';
|
||||
|
||||
@@ -48,7 +48,9 @@ class ProviderResource extends Resource
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('id')->label('ID')->searchable(),
|
||||
Tables\Columns\TextColumn::make('id')
|
||||
->label('ID')
|
||||
->searchable(),
|
||||
Tables\Columns\TextColumn::make('name')
|
||||
->description(function (Provider $record) {
|
||||
return "{$record->plans_count} plan(s) · {$record->regions_count} region(s)";
|
||||
@@ -71,12 +73,12 @@ class ProviderResource extends Resource
|
||||
Tables\Actions\Action::make('synchronize_provider')
|
||||
->label(__('Synchronize'))
|
||||
->tooltip(__('This will synchronize the latest data from this provider to your Ploi Core installation'))
|
||||
->icon('heroicon-o-refresh')
|
||||
->icon('heroicon-o-arrow-path')
|
||||
->action(function (Provider $record) {
|
||||
$provider = app(SynchronizeProviderAction::class)->execute($record->ploi_id);
|
||||
|
||||
Notification::make()
|
||||
->body(__('Provider :provider synchronized successfully.', ['provider' => $provider->name]))
|
||||
->title(__('Provider :provider synchronized successfully.', ['provider' => $provider->name]))
|
||||
->success()
|
||||
->send();
|
||||
}),
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace App\Filament\Resources\ProviderResource\Pages;
|
||||
|
||||
use Filament\Pages\Actions\Action;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
use App\Filament\Resources\ProviderResource;
|
||||
|
||||
@@ -14,14 +14,14 @@ class ListProviders extends ListRecords
|
||||
|
||||
protected static string $resource = ProviderResource::class;
|
||||
|
||||
protected function getActions(): array
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Action::make('synchronize_providers')
|
||||
Actions\Action::make('synchronize_providers')
|
||||
->label(__('Synchronize providers'))
|
||||
->icon('heroicon-o-refresh')
|
||||
->color('secondary')
|
||||
->url(route('filament.resources.providers.synchronize')),
|
||||
->icon('heroicon-o-arrow-path')
|
||||
->color('gray')
|
||||
->url(ProviderResource::getUrl('synchronize')),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ class SynchronizeProviders extends Page
|
||||
];
|
||||
}
|
||||
|
||||
protected function getActions(): array
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
|
||||
@@ -46,14 +46,14 @@ class AvailableProvidersOverview extends TableWidget
|
||||
return [
|
||||
Action::make('synchronize_provider')
|
||||
->label(__('Synchronize'))
|
||||
->icon('heroicon-o-refresh')
|
||||
->icon('heroicon-o-arrow-path')
|
||||
->action(function (AvailableProvider $record, self $livewire) {
|
||||
$provider = app(SynchronizeProviderAction::class)->execute($record->id);
|
||||
|
||||
$livewire->emit('$refresh');
|
||||
$livewire->dispatch('$refresh');
|
||||
|
||||
Notification::make()
|
||||
->body(__('Provider :provider synchronized successfully.', ['provider' => $provider->name]))
|
||||
->title(__('Provider :provider synchronized successfully.', ['provider' => $provider->name]))
|
||||
->success()
|
||||
->send();
|
||||
}),
|
||||
|
||||
@@ -5,8 +5,8 @@ namespace App\Filament\Resources;
|
||||
use Filament\Forms;
|
||||
use Filament\Tables;
|
||||
use App\Models\Redirect;
|
||||
use Filament\Resources\Form;
|
||||
use Filament\Resources\Table;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Tables\Table;
|
||||
use Filament\Resources\Resource;
|
||||
use App\Filament\Resources\RedirectResource\Pages;
|
||||
|
||||
@@ -14,7 +14,7 @@ class RedirectResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Redirect::class;
|
||||
|
||||
protected static ?string $navigationIcon = 'heroicon-o-external-link';
|
||||
protected static ?string $navigationIcon = 'heroicon-o-arrow-top-right-on-square';
|
||||
|
||||
protected static ?string $navigationGroup = 'Site management';
|
||||
|
||||
@@ -26,15 +26,11 @@ class RedirectResource extends Resource
|
||||
->schema([
|
||||
Forms\Components\TextInput::make('site_id'),
|
||||
Forms\Components\TextInput::make('server_id'),
|
||||
Forms\Components\TextInput::make('status')
|
||||
->maxLength(255),
|
||||
Forms\Components\TextInput::make('status'),
|
||||
Forms\Components\TextInput::make('ploi_id'),
|
||||
Forms\Components\TextInput::make('redirect_from')
|
||||
->maxLength(255),
|
||||
Forms\Components\TextInput::make('redirect_to')
|
||||
->maxLength(255),
|
||||
Forms\Components\TextInput::make('type')
|
||||
->maxLength(255),
|
||||
Forms\Components\TextInput::make('redirect_from'),
|
||||
Forms\Components\TextInput::make('redirect_to'),
|
||||
Forms\Components\TextInput::make('type'),
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -58,11 +54,12 @@ class RedirectResource extends Resource
|
||||
->searchable(),
|
||||
Tables\Columns\TextColumn::make('type')
|
||||
->label(__('Type')),
|
||||
Tables\Columns\BadgeColumn::make('status')
|
||||
->enum([
|
||||
Tables\Columns\TextColumn::make('status')
|
||||
->badge()
|
||||
->formatStateUsing(fn (string $state) => match ($state) {
|
||||
Redirect::STATUS_BUSY => __('Busy'),
|
||||
Redirect::STATUS_ACTIVE => __('Active'),
|
||||
])
|
||||
})
|
||||
->colors([
|
||||
'warning' => Redirect::STATUS_BUSY,
|
||||
'success' => Redirect::STATUS_ACTIVE,
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace App\Filament\Resources\RedirectResource\Pages;
|
||||
|
||||
use Filament\Pages\Actions;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
use App\Filament\Resources\RedirectResource;
|
||||
|
||||
@@ -10,7 +10,7 @@ class ListRedirects extends ListRecords
|
||||
{
|
||||
protected static string $resource = RedirectResource::class;
|
||||
|
||||
protected function getActions(): array
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\CreateAction::make(),
|
||||
|
||||
@@ -6,8 +6,8 @@ use Filament\Forms;
|
||||
use App\Models\User;
|
||||
use Filament\Tables;
|
||||
use App\Models\Server;
|
||||
use Filament\Resources\Form;
|
||||
use Filament\Resources\Table;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Tables\Table;
|
||||
use Filament\Resources\Resource;
|
||||
use Illuminate\Support\HtmlString;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
@@ -61,12 +61,13 @@ class ServerResource extends Resource
|
||||
Tables\Columns\TextColumn::make('name')
|
||||
->label(__('Name'))
|
||||
->searchable(),
|
||||
Tables\Columns\BadgeColumn::make('status')
|
||||
Tables\Columns\TextColumn::make('status')
|
||||
->label(__('Status'))
|
||||
->enum([
|
||||
->badge()
|
||||
->formatStateUsing(fn (string $state) => match ($state) {
|
||||
Server::STATUS_BUSY => __('Busy'),
|
||||
Server::STATUS_ACTIVE => __('Active'),
|
||||
])
|
||||
})
|
||||
->colors([
|
||||
'warning' => Server::STATUS_BUSY,
|
||||
'success' => Server::STATUS_ACTIVE,
|
||||
@@ -74,19 +75,27 @@ class ServerResource extends Resource
|
||||
Tables\Columns\TextColumn::make('users')
|
||||
->label(__('Users'))
|
||||
->wrap()
|
||||
->getStateUsing(function (Server $record) {
|
||||
->formatStateUsing(function (Server $record) {
|
||||
$state = $record
|
||||
->users
|
||||
->map(function (User $user) {
|
||||
return '<a href="' . route('filament.resources.users.edit', ['record' => $user]) . '" class="text-primary-600">' . $user->name . '</a>';
|
||||
return '<a href="' . UserResource::getUrl('edit', ['record' => $user]) . '" class="text-primary-600" style="white-space: nowrap">' . $user->name . '</a>';
|
||||
})
|
||||
->implode(', ') ?: '-';
|
||||
|
||||
return new HtmlString($state);
|
||||
})
|
||||
->searchable(query: function (Builder $query, string $search) {
|
||||
return $query->whereHas('users', function (Builder $query) use ($search) {
|
||||
return $query
|
||||
->where('name', 'LIKE', "%{$search}%")
|
||||
->orWhere('email', 'LIKE', "%{$search}%");
|
||||
});
|
||||
}),
|
||||
Tables\Columns\TextColumn::make('maximum_sites')
|
||||
->label(__('Max sites'))
|
||||
->formatStateUsing(fn (Server $record) => $record->maximum_sites . " (Current: {$record->sites_count})"),
|
||||
->formatStateUsing(fn (Server $record) => $record->maximum_sites . " (Current: {$record->sites_count})")
|
||||
->counts('sites'),
|
||||
Tables\Columns\TextColumn::make('ip')
|
||||
->label(__('IP')),
|
||||
Tables\Columns\TextColumn::make('created_at')
|
||||
@@ -101,9 +110,10 @@ class ServerResource extends Resource
|
||||
Tables\Actions\Action::make('synchronize_server')
|
||||
->label(__('Synchronize'))
|
||||
->tooltip(__('This will synchronize the latest data from this provider to your Ploi Core installation'))
|
||||
->icon('heroicon-o-refresh')
|
||||
->icon('heroicon-o-arrow-path')
|
||||
->action(fn (Server $record) => app(SynchronizeServerAction::class)->execute($record->ploi_id))
|
||||
->visible(fn (Server $record) => $record->status === Server::STATUS_ACTIVE),
|
||||
Tables\Actions\DeleteAction::make(),
|
||||
])
|
||||
->bulkActions([
|
||||
Tables\Actions\DeleteBulkAction::make(),
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace App\Filament\Resources\ServerResource\Pages;
|
||||
|
||||
use Filament\Pages\Actions;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
use App\Filament\Resources\ServerResource;
|
||||
|
||||
@@ -10,7 +10,7 @@ class EditServer extends EditRecord
|
||||
{
|
||||
protected static string $resource = ServerResource::class;
|
||||
|
||||
protected function getActions(): array
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\DeleteAction::make(),
|
||||
|
||||
@@ -2,36 +2,23 @@
|
||||
|
||||
namespace App\Filament\Resources\ServerResource\Pages;
|
||||
|
||||
use Filament\Pages\Actions\Action;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use App\Filament\Resources\ServerResource;
|
||||
|
||||
class ListServers extends ListRecords
|
||||
{
|
||||
protected static string $resource = ServerResource::class;
|
||||
|
||||
protected function getActions(): array
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Action::make('synchronize_servers')
|
||||
Actions\Action::make('synchronize_servers')
|
||||
->label(__('Synchronize servers'))
|
||||
->icon('heroicon-o-refresh')
|
||||
->color('secondary')
|
||||
->url(route('filament.resources.servers.synchronize')),
|
||||
...parent::getActions(),
|
||||
->icon('heroicon-o-arrow-path')
|
||||
->color('gray')
|
||||
->url(ServerResource::getUrl('synchronize')),
|
||||
...parent::getHeaderActions(),
|
||||
];
|
||||
}
|
||||
|
||||
protected function applySearchToTableQuery(Builder $query): Builder
|
||||
{
|
||||
if (filled($searchTerm = $this->getTableSearchQuery())) {
|
||||
$query
|
||||
->where('domain', 'LIKE', "%{$searchTerm}%")
|
||||
->orWhereHas('users', fn (Builder $query) => $query->where('name', 'LIKE', "%{$searchTerm}%"))
|
||||
->orWhereHas('users', fn (Builder $query) => $query->where('email', 'LIKE', "%{$searchTerm}%"));
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
|
||||
namespace App\Filament\Resources\ServerResource\Pages;
|
||||
|
||||
use Filament\Actions;
|
||||
use App\Models\Server;
|
||||
use App\Services\Ploi\Ploi;
|
||||
use Filament\Pages\Actions\Action;
|
||||
use Filament\Resources\Pages\Page;
|
||||
use Filament\Notifications\Notification;
|
||||
use App\Filament\Resources\ServerResource;
|
||||
@@ -24,15 +24,15 @@ class SynchronizeServers extends Page
|
||||
];
|
||||
}
|
||||
|
||||
protected function getActions(): array
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Action::make('synchronize_servers')
|
||||
Actions\Action::make('synchronize_servers')
|
||||
->label(__('Synchronize all servers'))
|
||||
->icon('heroicon-o-refresh')
|
||||
->icon('heroicon-o-arrow-path')
|
||||
->requiresConfirmation()
|
||||
->modalHeading('Synchronize servers')
|
||||
->modalSubheading('This will synchronize all the servers that are listed in the table, to your Ploi Core installation.')
|
||||
->modalDescription('This will synchronize all the servers that are listed in the table, to your Ploi Core installation.')
|
||||
->action(function () {
|
||||
$availableServers = Ploi::make()->synchronize()->servers()->getData();
|
||||
|
||||
@@ -51,7 +51,7 @@ class SynchronizeServers extends Page
|
||||
}
|
||||
|
||||
Notification::make()
|
||||
->body(__('Servers synchronized successfully.'))
|
||||
->title(__('Servers synchronized successfully.'))
|
||||
->success()
|
||||
->send();
|
||||
}),
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
|
||||
namespace App\Filament\Resources\ServerResource\RelationManagers;
|
||||
|
||||
use Filament\Resources\Form;
|
||||
use Filament\Resources\Table;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Tables\Table;
|
||||
use App\Filament\Resources\SiteResource;
|
||||
use Filament\Resources\RelationManagers\RelationManager;
|
||||
|
||||
@@ -23,12 +23,12 @@ class SitesRelationManager extends RelationManager
|
||||
return __('Sites');
|
||||
}
|
||||
|
||||
public static function form(Form $form): Form
|
||||
public function form(Form $form): Form
|
||||
{
|
||||
return SiteResource::form($form);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
public function table(Table $table): Table
|
||||
{
|
||||
return SiteResource::table($table);
|
||||
}
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
namespace App\Filament\Resources\ServerResource\RelationManagers;
|
||||
|
||||
use Filament\Tables;
|
||||
use Filament\Resources\Form;
|
||||
use Filament\Resources\Table;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Tables\Table;
|
||||
use App\Filament\Resources\UserResource;
|
||||
use Filament\Resources\RelationManagers\RelationManager;
|
||||
|
||||
@@ -24,18 +24,21 @@ class UsersRelationManager extends RelationManager
|
||||
return __('Users');
|
||||
}
|
||||
|
||||
public static function form(Form $form): Form
|
||||
public function form(Form $form): Form
|
||||
{
|
||||
return UserResource::form($form);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
public function table(Table $table): Table
|
||||
{
|
||||
return UserResource::table($table)
|
||||
->appendHeaderActions([
|
||||
Tables\Actions\AttachAction::make()->preloadRecordSelect(),
|
||||
->headerActions([
|
||||
...$table->getHeaderActions(),
|
||||
Tables\Actions\AttachAction::make()
|
||||
->preloadRecordSelect(),
|
||||
])
|
||||
->appendActions([
|
||||
->actions([
|
||||
...$table->getActions(),
|
||||
Tables\Actions\DetachAction::make(),
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ class AvailableServersOverview extends TableWidget
|
||||
return [
|
||||
Action::make('synchronize_server')
|
||||
->label(__('Synchronize'))
|
||||
->icon('heroicon-o-refresh')
|
||||
->icon('heroicon-o-arrow-path')
|
||||
->action(function (AvailableServer $record) {
|
||||
app(SynchronizeServerAction::class)->execute($record->id);
|
||||
}),
|
||||
|
||||
@@ -6,10 +6,11 @@ use Filament\Forms;
|
||||
use App\Models\Site;
|
||||
use App\Models\User;
|
||||
use Filament\Tables;
|
||||
use Filament\Resources\Form;
|
||||
use Filament\Resources\Table;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Tables\Table;
|
||||
use Filament\Resources\Resource;
|
||||
use Illuminate\Support\HtmlString;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use App\Actions\Site\SynchronizeSiteAction;
|
||||
use App\Filament\Resources\SiteResource\Pages;
|
||||
use App\Filament\Resources\SiteResource\RelationManagers;
|
||||
@@ -18,7 +19,7 @@ class SiteResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Site::class;
|
||||
|
||||
protected static ?string $navigationIcon = 'heroicon-o-code';
|
||||
protected static ?string $navigationIcon = 'heroicon-o-code-bracket';
|
||||
|
||||
protected static ?string $navigationGroup = 'Site management';
|
||||
|
||||
@@ -26,9 +27,6 @@ class SiteResource extends Resource
|
||||
|
||||
protected static ?string $recordTitleAttribute = 'domain';
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
public static function getLabel(): ?string
|
||||
{
|
||||
return __('Site');
|
||||
@@ -65,12 +63,14 @@ class SiteResource extends Resource
|
||||
->searchable(),
|
||||
Tables\Columns\TextColumn::make('server.name')
|
||||
->label(__('Server'))
|
||||
->sortable()
|
||||
->searchable(),
|
||||
Tables\Columns\BadgeColumn::make('status')
|
||||
->enum([
|
||||
Tables\Columns\TextColumn::make('status')
|
||||
->badge()
|
||||
->formatStateUsing(fn (string $state) => match ($state) {
|
||||
Site::STATUS_BUSY => __('Busy'),
|
||||
Site::STATUS_ACTIVE => __('Active'),
|
||||
])
|
||||
})
|
||||
->colors([
|
||||
'warning' => Site::STATUS_BUSY,
|
||||
'success' => Site::STATUS_ACTIVE,
|
||||
@@ -78,15 +78,23 @@ class SiteResource extends Resource
|
||||
->label(__('Status')),
|
||||
Tables\Columns\TextColumn::make('users')
|
||||
->label(__('Users'))
|
||||
->getStateUsing(function (Site $record) {
|
||||
->wrap()
|
||||
->formatStateUsing(function (Site $record) {
|
||||
$state = $record
|
||||
->users
|
||||
->map(function (User $user) {
|
||||
return '<a href="' . route('filament.resources.users.edit', ['record' => $user]) . '" class="text-primary-600">' . $user->name . '</a>';
|
||||
return '<a href="' . UserResource::getUrl('edit', ['record' => $user]) . '" class="text-primary-600" style="white-space: nowrap">' . $user->name . '</a>';
|
||||
})
|
||||
->implode(', ') ?: '-';
|
||||
|
||||
return new HtmlString($state);
|
||||
})
|
||||
->searchable(query: function (Builder $query, string $search) {
|
||||
return $query->whereHas('users', function (Builder $query) use ($search) {
|
||||
return $query
|
||||
->where('name', 'LIKE', "%{$search}%")
|
||||
->orWhere('email', 'LIKE', "%{$search}%");
|
||||
});
|
||||
}),
|
||||
Tables\Columns\TextColumn::make('created_at')
|
||||
->label(__('Date'))
|
||||
@@ -101,11 +109,12 @@ class SiteResource extends Resource
|
||||
Tables\Actions\Action::make('synchronize_site')
|
||||
->label(__('Synchronize'))
|
||||
->tooltip(__('This will synchronize the latest data from this provider to your Ploi Core installation'))
|
||||
->icon('heroicon-o-refresh')
|
||||
->icon('heroicon-o-arrow-path')
|
||||
->action(function (Site $record) {
|
||||
app(SynchronizeSiteAction::class)->execute($record->server->ploi_id, $record->ploi_id);
|
||||
})
|
||||
->visible(fn (Site $record) => $record->status === Site::STATUS_ACTIVE),
|
||||
Tables\Actions\DeleteAction::make(),
|
||||
])
|
||||
->bulkActions([
|
||||
Tables\Actions\DeleteBulkAction::make(),
|
||||
@@ -113,7 +122,7 @@ class SiteResource extends Resource
|
||||
->defaultSort('sites.created_at', 'desc');
|
||||
}
|
||||
|
||||
public static function getEloquentQuery(): \Illuminate\Database\Eloquent\Builder
|
||||
public static function getEloquentQuery(): Builder
|
||||
{
|
||||
return parent::getEloquentQuery()
|
||||
->with(['users', 'server']);
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace App\Filament\Resources\SiteResource\Pages;
|
||||
|
||||
use Filament\Pages\Actions;
|
||||
use Filament\Actions;
|
||||
use App\Filament\Resources\SiteResource;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
@@ -10,7 +10,7 @@ class EditSite extends EditRecord
|
||||
{
|
||||
protected static string $resource = SiteResource::class;
|
||||
|
||||
protected function getActions(): array
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\DeleteAction::make(),
|
||||
|
||||
@@ -2,11 +2,10 @@
|
||||
|
||||
namespace App\Filament\Resources\SiteResource\Pages;
|
||||
|
||||
use Filament\Actions;
|
||||
use App\Traits\HasPloi;
|
||||
use Filament\Pages\Actions\Action;
|
||||
use App\Filament\Resources\SiteResource;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class ListSites extends ListRecords
|
||||
{
|
||||
@@ -14,28 +13,15 @@ class ListSites extends ListRecords
|
||||
|
||||
protected static string $resource = SiteResource::class;
|
||||
|
||||
protected function getActions(): array
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Action::make('synchronize_sites')
|
||||
Actions\Action::make('synchronize_sites')
|
||||
->label(__('Synchronize sites'))
|
||||
->icon('heroicon-o-refresh')
|
||||
->color('secondary')
|
||||
->url(route('filament.resources.sites.synchronize')),
|
||||
|
||||
...parent::getActions()
|
||||
->icon('heroicon-o-arrow-path')
|
||||
->color('gray')
|
||||
->url(SiteResource::getUrl('synchronize')),
|
||||
...parent::getHeaderActions()
|
||||
];
|
||||
}
|
||||
|
||||
protected function applySearchToTableQuery(Builder $query): Builder
|
||||
{
|
||||
if (filled($searchTerm = $this->getTableSearchQuery())) {
|
||||
$query
|
||||
->where('domain', 'LIKE', "%{$searchTerm}%")
|
||||
->orWhereHas('users', fn (Builder $query) => $query->where('name', 'LIKE', "%{$searchTerm}%"))
|
||||
->orWhereHas('users', fn (Builder $query) => $query->where('email', 'LIKE', "%{$searchTerm}%"));
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
namespace App\Filament\Resources\SiteResource\Pages;
|
||||
|
||||
use App\Models\Site;
|
||||
use Filament\Actions;
|
||||
use App\Models\Server;
|
||||
use App\Services\Ploi\Ploi;
|
||||
use Filament\Pages\Actions\Action;
|
||||
use Filament\Resources\Pages\Page;
|
||||
use App\Filament\Resources\SiteResource;
|
||||
use Filament\Notifications\Notification;
|
||||
@@ -23,15 +23,15 @@ class SynchronizeSites extends Page
|
||||
];
|
||||
}
|
||||
|
||||
protected function getActions(): array
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Action::make('synchronize_sites')
|
||||
Actions\Action::make('synchronize_sites')
|
||||
->label(__('Synchronize all sites'))
|
||||
->icon('heroicon-o-refresh')
|
||||
->icon('heroicon-o-arrow-path')
|
||||
->requiresConfirmation()
|
||||
->modalHeading('Synchronize sites')
|
||||
->modalSubheading('This will synchronize all the sites that are listed in the table, to your Ploi Core installation.')
|
||||
->modalDescription('This will synchronize all the sites that are listed in the table, to your Ploi Core installation.')
|
||||
->action(function () {
|
||||
$availableSites = Ploi::make()->synchronize()->sites()->getData();
|
||||
|
||||
@@ -52,7 +52,7 @@ class SynchronizeSites extends Page
|
||||
}
|
||||
|
||||
Notification::make()
|
||||
->body(__('Sites synchronized successfully.'))
|
||||
->title(__('Sites synchronized successfully.'))
|
||||
->success()
|
||||
->send();
|
||||
}),
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
|
||||
namespace App\Filament\Resources\SiteResource\RelationManagers;
|
||||
|
||||
use Filament\Resources\Form;
|
||||
use Filament\Resources\Table;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Tables\Table;
|
||||
use App\Filament\Resources\CertificateResource;
|
||||
use Filament\Resources\RelationManagers\RelationManager;
|
||||
|
||||
@@ -13,12 +13,12 @@ class CertificatesRelationManager extends RelationManager
|
||||
|
||||
protected static ?string $recordTitleAttribute = 'domain';
|
||||
|
||||
public static function form(Form $form): Form
|
||||
public function form(Form $form): Form
|
||||
{
|
||||
return CertificateResource::form($form);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
public function table(Table $table): Table
|
||||
{
|
||||
return CertificateResource::table($table);
|
||||
}
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
|
||||
namespace App\Filament\Resources\SiteResource\RelationManagers;
|
||||
|
||||
use Filament\Resources\Form;
|
||||
use Filament\Resources\Table;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Tables\Table;
|
||||
use App\Filament\Resources\CronjobResource;
|
||||
use Filament\Resources\RelationManagers\RelationManager;
|
||||
|
||||
@@ -13,12 +13,12 @@ class CronjobsRelationManager extends RelationManager
|
||||
|
||||
protected static ?string $recordTitleAttribute = 'command';
|
||||
|
||||
public static function form(Form $form): Form
|
||||
public function form(Form $form): Form
|
||||
{
|
||||
return CronjobResource::form($form);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
public function table(Table $table): Table
|
||||
{
|
||||
return CronjobResource::table($table);
|
||||
}
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
|
||||
namespace App\Filament\Resources\SiteResource\RelationManagers;
|
||||
|
||||
use Filament\Resources\Form;
|
||||
use Filament\Resources\Table;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Tables\Table;
|
||||
use App\Filament\Resources\DatabaseResource;
|
||||
use Filament\Resources\RelationManagers\RelationManager;
|
||||
|
||||
@@ -13,12 +13,12 @@ class DatabasesRelationManager extends RelationManager
|
||||
|
||||
protected static ?string $recordTitleAttribute = 'name';
|
||||
|
||||
public static function form(Form $form): Form
|
||||
public function form(Form $form): Form
|
||||
{
|
||||
return DatabaseResource::form($form);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
public function table(Table $table): Table
|
||||
{
|
||||
return DatabaseResource::table($table);
|
||||
}
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
|
||||
namespace App\Filament\Resources\SiteResource\RelationManagers;
|
||||
|
||||
use Filament\Resources\Form;
|
||||
use Filament\Resources\Table;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Tables\Table;
|
||||
use App\Filament\Resources\RedirectResource;
|
||||
use Filament\Resources\RelationManagers\RelationManager;
|
||||
|
||||
@@ -13,12 +13,12 @@ class RedirectsRelationManager extends RelationManager
|
||||
|
||||
protected static ?string $recordTitleAttribute = 'from';
|
||||
|
||||
public static function form(Form $form): Form
|
||||
public function form(Form $form): Form
|
||||
{
|
||||
return RedirectResource::form($form);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
public function table(Table $table): Table
|
||||
{
|
||||
return RedirectResource::table($table);
|
||||
}
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
|
||||
namespace App\Filament\Resources\SiteResource\RelationManagers;
|
||||
|
||||
use Filament\Resources\Form;
|
||||
use Filament\Resources\Table;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Tables\Table;
|
||||
use App\Filament\Resources\SiteSystemUserResource;
|
||||
use Filament\Resources\RelationManagers\RelationManager;
|
||||
|
||||
@@ -13,12 +13,12 @@ class SystemUsersRelationManager extends RelationManager
|
||||
|
||||
protected static ?string $recordTitleAttribute = 'user_name';
|
||||
|
||||
public static function form(Form $form): Form
|
||||
public function form(Form $form): Form
|
||||
{
|
||||
return SiteSystemUserResource::form($form);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
public function table(Table $table): Table
|
||||
{
|
||||
return SiteSystemUserResource::table($table);
|
||||
}
|
||||
|
||||
@@ -2,11 +2,10 @@
|
||||
|
||||
namespace App\Filament\Resources\SiteResource\RelationManagers;
|
||||
|
||||
use Filament\Resources\Form;
|
||||
use Filament\Resources\Table;
|
||||
use Filament\Tables;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Tables\Table;
|
||||
use App\Filament\Resources\UserResource;
|
||||
use Filament\Tables\Actions\AttachAction;
|
||||
use Filament\Tables\Actions\DetachAction;
|
||||
use Filament\Resources\RelationManagers\RelationManager;
|
||||
|
||||
class UsersRelationManager extends RelationManager
|
||||
@@ -25,20 +24,22 @@ class UsersRelationManager extends RelationManager
|
||||
return __('Users');
|
||||
}
|
||||
|
||||
public static function form(Form $form): Form
|
||||
public function form(Form $form): Form
|
||||
{
|
||||
return UserResource::form($form);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
public function table(Table $table): Table
|
||||
{
|
||||
return UserResource::table($table)
|
||||
->headerActions([
|
||||
AttachAction::make()
|
||||
...$table->getHeaderActions(),
|
||||
Tables\Actions\AttachAction::make()
|
||||
->preloadRecordSelect(),
|
||||
])
|
||||
->appendActions([
|
||||
DetachAction::make(),
|
||||
->actions([
|
||||
...$table->getActions(),
|
||||
Tables\Actions\DetachAction::make(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ class AvailableSitesOverview extends TableWidget
|
||||
return [
|
||||
Action::make('synchronize_site')
|
||||
->label(__('Synchronize'))
|
||||
->icon('heroicon-o-refresh')
|
||||
->icon('heroicon-o-arrow-path')
|
||||
->action(function (AvailableSite $record) {
|
||||
app(SynchronizeSiteAction::class)->execute(ploiServerId: $record->server_id, ploiSiteId: $record->id);
|
||||
}),
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
namespace App\Filament\Resources;
|
||||
|
||||
use Filament\Tables;
|
||||
use Filament\Resources\Form;
|
||||
use Filament\Resources\Table;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Tables\Table;
|
||||
use App\Models\SiteSystemUser;
|
||||
use Filament\Resources\Resource;
|
||||
use App\Filament\Resources\SiteSystemUserResource\Pages;
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace App\Filament\Resources\SiteSystemUserResource\Pages;
|
||||
|
||||
use Filament\Pages\Actions;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
use App\Filament\Resources\SiteSystemUserResource;
|
||||
|
||||
@@ -10,7 +10,7 @@ class ListSiteSystemUsers extends ListRecords
|
||||
{
|
||||
protected static string $resource = SiteSystemUserResource::class;
|
||||
|
||||
protected function getActions(): array
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\CreateAction::make(),
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
namespace App\Filament\Resources;
|
||||
|
||||
use Filament\Tables;
|
||||
use Filament\Resources\Form;
|
||||
use Filament\Resources\Table;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Tables\Table;
|
||||
use Filament\Resources\Resource;
|
||||
use Laravel\Cashier\Subscription;
|
||||
use App\Filament\Resources\SubscriptionResource\Pages;
|
||||
@@ -13,7 +13,7 @@ class SubscriptionResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Subscription::class;
|
||||
|
||||
protected static ?string $navigationIcon = 'heroicon-o-cash';
|
||||
protected static ?string $navigationIcon = 'heroicon-o-banknotes';
|
||||
|
||||
protected static ?int $navigationSort = 4;
|
||||
|
||||
@@ -39,8 +39,9 @@ class SubscriptionResource extends Resource
|
||||
->url(fn ($record) => UserResource::getUrl('edit', ['record' => $record])),
|
||||
Tables\Columns\TextColumn::make('stripe_id')->searchable(),
|
||||
Tables\Columns\TextColumn::make('stripe_plan')->searchable(),
|
||||
Tables\Columns\BadgeColumn::make('stripe_status')
|
||||
Tables\Columns\TextColumn::make('stripe_status')
|
||||
->label('Status')
|
||||
->badge()
|
||||
->colors([
|
||||
'success' => \Stripe\Subscription::STATUS_ACTIVE,
|
||||
'warning' => \Stripe\Subscription::STATUS_PAST_DUE,
|
||||
@@ -55,6 +56,7 @@ class SubscriptionResource extends Resource
|
||||
])
|
||||
->actions([
|
||||
// Tables\Actions\EditAction::make(),
|
||||
Tables\Actions\DeleteAction::make(),
|
||||
])
|
||||
->bulkActions([
|
||||
Tables\Actions\DeleteBulkAction::make(),
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace App\Filament\Resources\SubscriptionResource\Pages;
|
||||
|
||||
use Filament\Pages\Actions;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
use App\Filament\Resources\SubscriptionResource;
|
||||
|
||||
@@ -10,7 +10,7 @@ class EditSubscription extends EditRecord
|
||||
{
|
||||
protected static string $resource = SubscriptionResource::class;
|
||||
|
||||
protected function getActions(): array
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\DeleteAction::make(),
|
||||
|
||||
@@ -2,14 +2,12 @@
|
||||
|
||||
namespace App\Filament\Resources;
|
||||
|
||||
use Filament\Resources\Form;
|
||||
use Filament\Tables;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Tables\Table;
|
||||
use App\Models\SupportTicket;
|
||||
use Filament\Resources\Table;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Columns\BadgeColumn;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Filament\Tables\Filters\MultiSelectFilter;
|
||||
use App\Filament\Resources\SupportTicketResource\Pages;
|
||||
|
||||
class SupportTicketResource extends Resource
|
||||
@@ -18,18 +16,18 @@ class SupportTicketResource extends Resource
|
||||
|
||||
protected static ?string $navigationGroup = 'Support';
|
||||
|
||||
protected static ?string $navigationIcon = 'heroicon-o-support';
|
||||
protected static ?string $navigationIcon = 'heroicon-o-lifebuoy';
|
||||
|
||||
protected static ?string $label = 'Ticker';
|
||||
protected static ?string $label = 'Ticket';
|
||||
|
||||
protected static ?string $pluralLabel = 'Tickets';
|
||||
|
||||
protected static function shouldRegisterNavigation(): bool
|
||||
public static function shouldRegisterNavigation(): bool
|
||||
{
|
||||
return (bool) setting('support');
|
||||
return (bool)setting('support');
|
||||
}
|
||||
|
||||
protected static function getNavigationBadge(): ?string
|
||||
public static function getNavigationBadge(): ?string
|
||||
{
|
||||
return static::getEloquentQuery()->count();
|
||||
}
|
||||
@@ -46,32 +44,34 @@ class SupportTicketResource extends Resource
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
BadgeColumn::make('status')
|
||||
Tables\Columns\TextColumn::make('status')
|
||||
->label(__('Status'))
|
||||
->enum([
|
||||
->badge()
|
||||
->formatStateUsing(fn (string $state) => match ($state) {
|
||||
SupportTicket::STATUS_OPEN => __('Open'),
|
||||
SupportTicket::STATUS_CLOSED => __('Closed'),
|
||||
SupportTicket::STATUS_CUSTOMER_REPLY => __('Customer Reply'),
|
||||
SupportTicket::STATUS_SUPPORT_REPLY => __('Support Reply'),
|
||||
])
|
||||
})
|
||||
->colors([
|
||||
'primary' => [SupportTicket::STATUS_OPEN, SupportTicket::STATUS_SUPPORT_REPLY, SupportTicket::STATUS_CUSTOMER_REPLY],
|
||||
'danger' => SupportTicket::STATUS_CLOSED,
|
||||
])
|
||||
->wrap(false),
|
||||
TextColumn::make('title')
|
||||
Tables\Columns\TextColumn::make('title')
|
||||
->searchable()
|
||||
->sortable(),
|
||||
TextColumn::make('replies_count')
|
||||
Tables\Columns\TextColumn::make('replies_count')
|
||||
->label(__('Replies'))
|
||||
->getStateUsing(fn (SupportTicket $record) => $record->replies->count()),
|
||||
TextColumn::make('user.name')
|
||||
Tables\Columns\TextColumn::make('user.name')
|
||||
->searchable()
|
||||
->sortable(),
|
||||
])
|
||||
->filters([
|
||||
MultiSelectFilter::make('status')
|
||||
Tables\Filters\SelectFilter::make('status')
|
||||
->label(__('Status'))
|
||||
->multiple()
|
||||
->options([
|
||||
SupportTicket::STATUS_OPEN => __('Open'),
|
||||
SupportTicket::STATUS_CLOSED => __('Closed'),
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace App\Filament\Resources\SupportTicketResource\Pages;
|
||||
|
||||
use Filament\Pages\Actions\CreateAction;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
use App\Filament\Resources\SupportTicketResource;
|
||||
|
||||
@@ -10,10 +10,10 @@ class ListSupportTickets extends ListRecords
|
||||
{
|
||||
protected static string $resource = SupportTicketResource::class;
|
||||
|
||||
protected function getActions(): array
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
CreateAction::make(),
|
||||
Actions\CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
|
||||
namespace App\Filament\Resources\SupportTicketResource\Pages;
|
||||
|
||||
use Filament\Actions;
|
||||
use App\Models\SupportTicket;
|
||||
use Filament\Pages\Actions\Action;
|
||||
use Filament\Resources\Pages\Page;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
@@ -31,36 +31,36 @@ class ViewSupportTicket extends Page
|
||||
return __('View ticket') . ': ' . $this->record->title;
|
||||
}
|
||||
|
||||
protected function getActions(): array
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Action::make('close')
|
||||
Actions\Action::make('close')
|
||||
->label(__('Close'))
|
||||
->action(function (self $livewire) {
|
||||
$livewire->record->status = SupportTicket::STATUS_CLOSED;
|
||||
$livewire->record->save();
|
||||
|
||||
Notification::make()
|
||||
->body(__('Ticket closed'))
|
||||
->title(__('Ticket closed'))
|
||||
->success()
|
||||
->send();
|
||||
|
||||
$livewire->redirectRoute('filament.resources.support-tickets.view', $livewire->record);
|
||||
$livewire->redirect(SupportTicketResource::getUrl('view', ['record' => $livewire->getRecord()]));
|
||||
})
|
||||
->visible(fn (self $livewire) => $livewire->record->status !== SupportTicket::STATUS_CLOSED)
|
||||
->color('danger'),
|
||||
Action::make('reopen')
|
||||
Actions\Action::make('reopen')
|
||||
->label(__('Reopen'))
|
||||
->action(function (self $livewire) {
|
||||
$livewire->record->status = SupportTicket::STATUS_OPEN;
|
||||
$livewire->record->save();
|
||||
|
||||
Notification::make()
|
||||
->body(__('Ticket reopened'))
|
||||
->title(__('Ticket reopened'))
|
||||
->success()
|
||||
->send();
|
||||
|
||||
$livewire->redirectRoute('filament.resources.support-tickets.view', $livewire->record);
|
||||
$livewire->redirect(SupportTicketResource::getUrl('view', ['record' => $livewire->getRecord()]));
|
||||
})
|
||||
->visible(fn (self $livewire) => $livewire->record->status === SupportTicket::STATUS_CLOSED)
|
||||
->color('primary'),
|
||||
@@ -100,10 +100,10 @@ class ViewSupportTicket extends Page
|
||||
Mail::to($this->record->user)->send(new TicketRepliedToEmail($this->record));
|
||||
|
||||
$this->form->fill();
|
||||
$this->emit('$refresh');
|
||||
$this->dispatch('$refresh');
|
||||
|
||||
Notification::make()
|
||||
->body(__('Reply sent'))
|
||||
->title(__('Reply sent'))
|
||||
->success()
|
||||
->send();
|
||||
}
|
||||
|
||||
@@ -5,8 +5,8 @@ namespace App\Filament\Resources;
|
||||
use Filament\Forms;
|
||||
use App\Models\User;
|
||||
use Filament\Tables;
|
||||
use Filament\Resources\Form;
|
||||
use Filament\Resources\Table;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Tables\Table;
|
||||
use Filament\Resources\Resource;
|
||||
use STS\FilamentImpersonate\Impersonate;
|
||||
use App\Filament\Resources\UserResource\Pages;
|
||||
@@ -107,8 +107,11 @@ class UserResource extends Resource
|
||||
//
|
||||
])
|
||||
->actions([
|
||||
Impersonate::make('impersonate')->tooltip('Login as this user (impersonate)'),
|
||||
Impersonate::make('impersonate')
|
||||
->tooltip('Login as this user (impersonate)')
|
||||
->visible(fn () => config('core.impersonation')),
|
||||
Tables\Actions\EditAction::make(),
|
||||
Tables\Actions\DeleteAction::make(),
|
||||
])
|
||||
->bulkActions([
|
||||
Tables\Actions\DeleteBulkAction::make(),
|
||||
|
||||
@@ -2,10 +2,21 @@
|
||||
|
||||
namespace App\Filament\Resources\UserResource\Pages;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use App\Filament\Resources\UserResource;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreateUser extends CreateRecord
|
||||
{
|
||||
protected static string $resource = UserResource::class;
|
||||
|
||||
protected function handleRecordCreation(array $data): Model
|
||||
{
|
||||
$model = $this->getModel();
|
||||
$record = new $model;
|
||||
$record->forceFill($data);
|
||||
$record->save();
|
||||
|
||||
return $record;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,9 +2,10 @@
|
||||
|
||||
namespace App\Filament\Resources\UserResource\Pages;
|
||||
|
||||
use Filament\Pages\Actions;
|
||||
use Filament\Actions;
|
||||
use Filament\Forms\Components\Toggle;
|
||||
use App\Actions\User\DeleteUserAction;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use App\Filament\Resources\UserResource;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
@@ -13,17 +14,25 @@ class EditUser extends EditRecord
|
||||
{
|
||||
protected static string $resource = UserResource::class;
|
||||
|
||||
protected function getActions(): array
|
||||
protected function handleRecordUpdate(Model $record, array $data): Model
|
||||
{
|
||||
$record->forceFill($data);
|
||||
$record->save();
|
||||
|
||||
return $record;
|
||||
}
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\Action::make('two_factor_authentication')
|
||||
->label(__('Disable two-factor authentication'))
|
||||
->color('secondary')
|
||||
->color('gray')
|
||||
->action(function () {
|
||||
$this->record->disableTwoFactorAuth();
|
||||
|
||||
Notification::make()
|
||||
->body(__('Two-factor authentication disabled'))
|
||||
->title(__('Two-factor authentication disabled'))
|
||||
->success()
|
||||
->send();
|
||||
})
|
||||
@@ -41,11 +50,11 @@ class EditUser extends EditRecord
|
||||
app(DeleteUserAction::class)->execute($this->getRecord(), $data['remove_all_data']);
|
||||
|
||||
Notification::make()
|
||||
->body(__('User deleted'))
|
||||
->title(__('User deleted'))
|
||||
->success()
|
||||
->send();
|
||||
|
||||
$this->redirectRoute('filament.resources.users.index');
|
||||
$this->redirect(UserResource::getUrl());
|
||||
})
|
||||
->color('danger'),
|
||||
];
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace App\Filament\Resources\UserResource\Pages;
|
||||
|
||||
use Filament\Pages\Actions;
|
||||
use Filament\Actions;
|
||||
use App\Filament\Resources\UserResource;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
@@ -10,7 +10,7 @@ class ListUsers extends ListRecords
|
||||
{
|
||||
protected static string $resource = UserResource::class;
|
||||
|
||||
protected function getActions(): array
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\CreateAction::make(),
|
||||
|
||||
@@ -2,11 +2,9 @@
|
||||
|
||||
namespace App\Filament\Resources\UserResource\RelationManagers;
|
||||
|
||||
use Filament\Resources\Form;
|
||||
use Filament\Resources\Table;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Tables\Table;
|
||||
use App\Filament\Resources\ServerResource;
|
||||
use Illuminate\Database\Eloquent\Relations\Relation;
|
||||
use Filament\Resources\RelationManagers\RelationManager;
|
||||
|
||||
class ServersRelationManager extends RelationManager
|
||||
@@ -15,19 +13,13 @@ class ServersRelationManager extends RelationManager
|
||||
|
||||
protected static ?string $recordTitleAttribute = 'name';
|
||||
|
||||
public static function form(Form $form): Form
|
||||
public function form(Form $form): Form
|
||||
{
|
||||
return ServerResource::form($form);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
public function table(Table $table): Table
|
||||
{
|
||||
return ServerResource::table($table);
|
||||
}
|
||||
|
||||
protected function getTableQuery(): Builder|Relation
|
||||
{
|
||||
return parent::getTableQuery()
|
||||
->withCount('sites');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
|
||||
namespace App\Filament\Resources\UserResource\RelationManagers;
|
||||
|
||||
use Filament\Resources\Form;
|
||||
use Filament\Resources\Table;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Tables\Table;
|
||||
use App\Filament\Resources\SiteResource;
|
||||
use Filament\Resources\RelationManagers\RelationManager;
|
||||
|
||||
@@ -13,12 +13,12 @@ class SitesRelationManager extends RelationManager
|
||||
|
||||
protected static ?string $recordTitleAttribute = 'domain';
|
||||
|
||||
public static function form(Form $form): Form
|
||||
public function form(Form $form): Form
|
||||
{
|
||||
return SiteResource::form($form);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
public function table(Table $table): Table
|
||||
{
|
||||
return SiteResource::table($table);
|
||||
}
|
||||
|
||||
@@ -5,7 +5,9 @@ namespace App\Filament\Widgets;
|
||||
use App\Models\Site;
|
||||
use App\Models\User;
|
||||
use App\Models\Server;
|
||||
use Filament\Widgets\StatsOverviewWidget\Card;
|
||||
use App\Filament\Resources\SiteResource;
|
||||
use App\Filament\Resources\UserResource;
|
||||
use App\Filament\Resources\ServerResource;
|
||||
use Filament\Widgets\StatsOverviewWidget as BaseWidget;
|
||||
|
||||
class StatsOverview extends BaseWidget
|
||||
@@ -13,14 +15,14 @@ class StatsOverview extends BaseWidget
|
||||
protected function getCards(): array
|
||||
{
|
||||
return [
|
||||
Card::make(__('Servers'), Server::count())
|
||||
->url(route('filament.resources.servers.index'))
|
||||
BaseWidget\Stat::make(__('Servers'), Server::count())
|
||||
->url(ServerResource::getUrl())
|
||||
->icon('heroicon-o-server'),
|
||||
Card::make(__('Sites'), Site::count())
|
||||
->url(route('filament.resources.sites.index'))
|
||||
BaseWidget\Stat::make(__('Sites'), Site::count())
|
||||
->url(SiteResource::getUrl())
|
||||
->icon('heroicon-o-globe-alt'),
|
||||
Card::make(__('Users'), User::count())
|
||||
->url(route('filament.resources.users.index'))
|
||||
BaseWidget\Stat::make(__('Users'), User::count())
|
||||
->url(UserResource::getUrl())
|
||||
->icon('heroicon-o-user'),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -2,8 +2,9 @@
|
||||
|
||||
namespace App\Filament\Widgets;
|
||||
|
||||
use Filament\Tables;
|
||||
use App\Models\SystemLog;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Filament\Widgets\TableWidget as BaseWidget;
|
||||
|
||||
@@ -11,27 +12,28 @@ class SystemLogs extends BaseWidget
|
||||
{
|
||||
protected int|string|array $columnSpan = 'full';
|
||||
|
||||
protected int $defaultTableRecordsPerPageSelectOption = 10;
|
||||
|
||||
protected function getTableQuery(): Builder
|
||||
public function table(Table $table): Table
|
||||
{
|
||||
return SystemLog::query()
|
||||
->latest()
|
||||
->with('model');
|
||||
}
|
||||
|
||||
protected function getTableColumns(): array
|
||||
{
|
||||
return [
|
||||
TextColumn::make(__('Title'))
|
||||
->formatStateUsing(fn (SystemLog $record) => __($record->title, [
|
||||
'site' => $record->model->domain ?? '-Unknown-',
|
||||
'database' => $record->model->name ?? '-Unknown-',
|
||||
]))
|
||||
->description(fn (SystemLog $record) => __($record->description, [
|
||||
'site' => $record->model->domain ?? '-Unknown-',
|
||||
'database' => $record->model->name ?? '-Unknown-',
|
||||
])),
|
||||
];
|
||||
return $table
|
||||
->query(fn (): Builder => SystemLog::query()->with('model'))
|
||||
->defaultSort(fn (Builder $query) => $query->latest())
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('title')
|
||||
->label(__('Title'))
|
||||
->formatStateUsing(fn (SystemLog $record) => __($record->title, [
|
||||
'site' => $record->model->domain ?? '-Unknown-',
|
||||
'database' => $record->model->name ?? '-Unknown-',
|
||||
]))
|
||||
->description(fn (SystemLog $record) => __($record->description, [
|
||||
'site' => $record->model->domain ?? '-Unknown-',
|
||||
'database' => $record->model->name ?? '-Unknown-',
|
||||
]))
|
||||
->searchable()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('created_at')
|
||||
->label(__('Date'))
|
||||
->dateTime()
|
||||
->sortable()
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ class ServerController extends Controller
|
||||
]);
|
||||
|
||||
$server = app(CreateServerAction::class)->execute(
|
||||
ServerData::validate($data)
|
||||
ServerData::validateAndCreate($data)
|
||||
);
|
||||
|
||||
return response(content: ['data' => ServerData::from($server->refresh())->toArray()], status: 201);
|
||||
|
||||
@@ -29,7 +29,7 @@ class SiteController extends Controller
|
||||
]);
|
||||
|
||||
$site = app(CreateSiteAction::class)->execute(
|
||||
SiteData::validate($data)
|
||||
SiteData::validateAndCreate($data)
|
||||
);
|
||||
|
||||
$site->refresh();
|
||||
|
||||
@@ -32,7 +32,7 @@ class UserController extends Controller
|
||||
'requires_password_for_ftp' => ['nullable'],
|
||||
]);
|
||||
|
||||
$userData = UserData::validate($data);
|
||||
$userData = UserData::validateAndCreate($data);
|
||||
|
||||
$user = User::create($userData->toArray());
|
||||
|
||||
@@ -50,7 +50,7 @@ class UserController extends Controller
|
||||
'requires_password_for_ftp' => [],
|
||||
]);
|
||||
|
||||
$userData = UserData::validate($data);
|
||||
$userData = UserData::validateAndCreate($data);
|
||||
|
||||
$user->update(
|
||||
Arr::only($userData->toArray(), array_keys($data))
|
||||
|
||||
@@ -151,11 +151,11 @@ class ProfileBillingController extends Controller
|
||||
$planId = $plan->stripe_plan_id;
|
||||
|
||||
// Only do something if the user is not already subscribed to this plan.
|
||||
if ($user->subscribedToPlan($planId, 'default')) {
|
||||
if ($user->subscribedToPrice($planId, 'default')) {
|
||||
return redirect()->route('profile.billing.index')->with('error', 'You did not select a different plan');
|
||||
}
|
||||
|
||||
// If the user is already subscribed to the default plan, we have to swap it. Otherwise create a new one.
|
||||
// If the user is already subscribed to the default plan, we have to swap it. Otherwise, create a new one.
|
||||
try {
|
||||
if ($user->subscribed('default')) {
|
||||
$user->subscription('default')->swap($planId);
|
||||
@@ -226,6 +226,7 @@ class ProfileBillingController extends Controller
|
||||
Package::CURRENCY_INR => 'INR ₹',
|
||||
Package::CURRENCY_THB => 'THB ',
|
||||
Package::CURRENCY_BRL => 'BRL R$ ',
|
||||
Package::CURRENCY_NZD => 'NZD $ ',
|
||||
];
|
||||
|
||||
return $currencies[strtolower($key)] ?? '$';
|
||||
|
||||
@@ -3,12 +3,14 @@
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Server;
|
||||
use App\Models\ProviderPlan;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Jobs\Servers\DeleteServer;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use App\Http\Resources\ServerResource;
|
||||
use App\DataTransferObjects\ServerData;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use App\Actions\Server\CreateServerAction;
|
||||
use App\Http\Requests\ServerUpdateRequest;
|
||||
|
||||
@@ -33,6 +35,12 @@ class ServerController extends Controller
|
||||
{
|
||||
$this->authorize('create', Server::class);
|
||||
|
||||
if ($package = $request->user()->package) {
|
||||
if ($package->maximum_servers > 0 && $request->user()->servers()->count() >= $package->maximum_servers) {
|
||||
return redirect()->back()->withErrors(['name' => 'You have received the maximum servers you\'re allowed to create.']);
|
||||
}
|
||||
}
|
||||
|
||||
$data = $request->validate([
|
||||
'name' => ['required'],
|
||||
'provider_id' => ['required'],
|
||||
@@ -44,7 +52,7 @@ class ServerController extends Controller
|
||||
$data['user_id'] = Auth::id();
|
||||
|
||||
app(CreateServerAction::class)->execute(
|
||||
ServerData::validate($data)
|
||||
ServerData::validateAndCreate($data)
|
||||
);
|
||||
|
||||
return redirect()->route('servers.index');
|
||||
@@ -95,19 +103,29 @@ class ServerController extends Controller
|
||||
|
||||
public function plansAndRegions(Request $request, $providerId)
|
||||
{
|
||||
$provider = $request->user()->package->providers()->findOrFail($providerId);
|
||||
$package = $request->user()->package;
|
||||
|
||||
$regions = $provider->regions()
|
||||
$provider = $package->providers()->findOrFail($providerId);
|
||||
|
||||
$regions = $provider
|
||||
->regions()
|
||||
->when($provider->allowed_regions, function ($query) use ($provider) {
|
||||
return $query->whereIn('id', $provider->allowed_regions);
|
||||
})
|
||||
->pluck('label', 'id');
|
||||
|
||||
$plans = $provider->plans()
|
||||
$plans = $provider
|
||||
->plans()
|
||||
->when($provider->allowed_plans, function ($query) use ($provider) {
|
||||
return $query->whereIn('id', $provider->allowed_plans);
|
||||
})
|
||||
->pluck('label', 'id');
|
||||
->when($package->providerPlans()->whereBelongsTo($provider)->exists(), function (Builder $query) use ($provider, $package) {
|
||||
return $query->whereIn('id', $package->providerPlans()->whereBelongsTo($provider)->pluck('provider_plans.id'));
|
||||
})
|
||||
->get()
|
||||
->mapWithKeys(function (ProviderPlan $providerPlan) {
|
||||
return [$providerPlan->id => $providerPlan->label ?? $providerPlan->plan_id];
|
||||
});
|
||||
|
||||
return [
|
||||
'regions' => $regions,
|
||||
|
||||
@@ -77,7 +77,7 @@ class SiteController extends Controller
|
||||
$request->merge(['user_id' => auth()->id()]);
|
||||
|
||||
$site = app(CreateSiteAction::class)->execute(
|
||||
SiteData::validate($request)
|
||||
SiteData::validateAndCreate($request)
|
||||
);
|
||||
|
||||
return $site
|
||||
|
||||
@@ -3,9 +3,7 @@
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Filament\Notifications\Notification;
|
||||
use Illuminate\Http\Request;
|
||||
use Livewire\Livewire;
|
||||
|
||||
class Demo
|
||||
{
|
||||
|
||||
@@ -11,12 +11,12 @@ class HasAccessToThisGroup
|
||||
public function handle(Request $request, Closure $next, $group)
|
||||
{
|
||||
if ($group === 'servers') {
|
||||
$package = $request->user()->package ?? [];
|
||||
$package = $request->user()->package ?? null;
|
||||
|
||||
if (
|
||||
!Arr::get($package->server_permissions, 'create', false) &&
|
||||
!Arr::get($package->server_permissions, 'update', false) &&
|
||||
!Arr::get($package->server_permissions, 'delete', false)
|
||||
!Arr::get($package->server_permissions ?? [], 'create', false) &&
|
||||
!Arr::get($package->server_permissions ?? [], 'update', false) &&
|
||||
!Arr::get($package->server_permissions ?? [], 'delete', false)
|
||||
) {
|
||||
abort(404);
|
||||
}
|
||||
|
||||
@@ -8,22 +8,12 @@ use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class SiteAppRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
public function authorize(): bool
|
||||
{
|
||||
return auth()->check();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'type' => [
|
||||
@@ -32,7 +22,6 @@ class SiteAppRequest extends FormRequest
|
||||
Rule::in([
|
||||
Site::PROJECT_WORDPRESS,
|
||||
Site::PROJECT_NEXTCLOUD,
|
||||
Site::PROJECT_OCTOBERCMS
|
||||
])
|
||||
]
|
||||
];
|
||||
|
||||
@@ -16,18 +16,11 @@ class InstallApp implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, HasPloi;
|
||||
|
||||
public Site $site;
|
||||
public $type;
|
||||
public $options;
|
||||
|
||||
public function __construct(Site $site, string $type = Site::PROJECT_WORDPRESS, array $options = [])
|
||||
public function __construct(public Site $site, public string $type = Site::PROJECT_WORDPRESS, public array $options = [])
|
||||
{
|
||||
$this->site = $site;
|
||||
$this->type = $type;
|
||||
$this->options = $options;
|
||||
}
|
||||
|
||||
public function handle()
|
||||
public function handle(): void
|
||||
{
|
||||
$response = $this->getPloi()
|
||||
->server($this->site->server->ploi_id)
|
||||
|
||||
@@ -44,11 +44,9 @@ class CreateDatabase implements ShouldQueue
|
||||
->databases()
|
||||
->create($this->database->name, $databaseUser->name, $this->password);
|
||||
|
||||
ray($ploiDatabase);
|
||||
$this->database->ploi_id = $ploiDatabase->id;
|
||||
$this->database->save();
|
||||
|
||||
ray($ploiDatabase);
|
||||
$databaseUser->ploi_id = $ploiDatabase->users[0]->id;
|
||||
$databaseUser->save();
|
||||
|
||||
|
||||
@@ -14,27 +14,11 @@ class ChangePhpVersion implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, HasPloi;
|
||||
|
||||
public $site;
|
||||
public $version;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @param Site $site
|
||||
* @param string $version
|
||||
*/
|
||||
public function __construct(Site $site, $version = '7.4')
|
||||
public function __construct(public Site $site, public $version = '8.2')
|
||||
{
|
||||
$this->site = $site;
|
||||
$this->version = $version;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
public function handle(): void
|
||||
{
|
||||
$this->getPloi()->server($this->site->server->ploi_id)->sites($this->site->ploi_id)->phpVersion($this->version);
|
||||
|
||||
|
||||
@@ -34,6 +34,7 @@ class CreateSite implements ShouldQueue
|
||||
);
|
||||
|
||||
$this->site->ploi_id = $ploiSite->data->id;
|
||||
$this->site->php_version = $ploiSite->data->php_version ?? 8.2;
|
||||
$this->site->save();
|
||||
|
||||
// Lets fetch the status after 5 seconds
|
||||
|
||||
@@ -4,7 +4,9 @@ namespace App\Models;
|
||||
|
||||
use App\Casts\PermissionCast;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
|
||||
class Package extends Model
|
||||
{
|
||||
@@ -19,6 +21,7 @@ class Package extends Model
|
||||
const CURRENCY_INR = 'inr';
|
||||
const CURRENCY_THB = 'thb';
|
||||
const CURRENCY_BRL = 'brl';
|
||||
const CURRENCY_NZD = 'nz';
|
||||
|
||||
public $fillable = [
|
||||
'name',
|
||||
@@ -38,19 +41,24 @@ class Package extends Model
|
||||
'server_permissions' => PermissionCast::class,
|
||||
];
|
||||
|
||||
public function users()
|
||||
public function users(): HasMany
|
||||
{
|
||||
return $this->hasMany(User::class);
|
||||
}
|
||||
|
||||
public function providers()
|
||||
public function providers(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(Provider::class);
|
||||
return $this->belongsToMany(Provider::class)->using(PackageProvider::class);
|
||||
}
|
||||
|
||||
protected static function booted()
|
||||
public function providerPlans(): BelongsToMany
|
||||
{
|
||||
static::deleting(function ($package) {
|
||||
return $this->belongsToMany(ProviderPlan::class);
|
||||
}
|
||||
|
||||
protected static function booted(): void
|
||||
{
|
||||
static::deleting(function (self $package) {
|
||||
$package->users()->update(['package_id' => null]);
|
||||
});
|
||||
}
|
||||
|
||||
26
app/Models/PackageProvider.php
Normal file
26
app/Models/PackageProvider.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Relations\Pivot;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class PackageProvider extends Pivot
|
||||
{
|
||||
protected static function booted(): void
|
||||
{
|
||||
static::deleting(function (self $packageProvider) {
|
||||
$packageProvider->package->providerPlans()->whereBelongsTo($packageProvider->provider)->detach();
|
||||
});
|
||||
}
|
||||
|
||||
public function package(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Package::class);
|
||||
}
|
||||
|
||||
public function provider(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Provider::class);
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user