Apply style
This commit is contained in:
@@ -27,23 +27,23 @@ class ServerData extends Data
|
||||
#[StringType]
|
||||
public ?string $status = null,
|
||||
#[StringType,
|
||||
AlphaDash,
|
||||
Max(40)]
|
||||
AlphaDash,
|
||||
Max(40)]
|
||||
public string $name,
|
||||
#[NotIn(0),
|
||||
Exists(Provider::class, 'id')]
|
||||
Exists(Provider::class, 'id')]
|
||||
public int $provider_id,
|
||||
#[NotIn(0),
|
||||
Exists(ProviderRegion::class, 'id')]
|
||||
Exists(ProviderRegion::class, 'id')]
|
||||
public int $provider_region_id,
|
||||
#[NotIn(0),
|
||||
Exists(ProviderPlan::class, 'id')]
|
||||
Exists(ProviderPlan::class, 'id')]
|
||||
public int $provider_plan_id,
|
||||
#[StringType,
|
||||
In(['mysql', 'mariadb', 'postgresql', 'postgresql13'])]
|
||||
In(['mysql', 'mariadb', 'postgresql', 'postgresql13'])]
|
||||
public string $database_type,
|
||||
#[Exists(User::class, 'id'),
|
||||
IntegerType]
|
||||
IntegerType]
|
||||
public ?int $user_id = null,
|
||||
public ?Carbon $created_at = null,
|
||||
) {
|
||||
|
||||
@@ -28,7 +28,7 @@ class SiteData extends Data
|
||||
#[StringType, CustomRule(Hostname::class, ValidateMaximumSites::class)]
|
||||
public ?string $domain = null,
|
||||
#[Exists(User::class, 'id'),
|
||||
IntegerType]
|
||||
IntegerType]
|
||||
public ?int $user_id = null,
|
||||
public ?Carbon $created_at = null,
|
||||
) {
|
||||
|
||||
@@ -2,20 +2,13 @@
|
||||
|
||||
namespace App\DataTransferObjects\Support;
|
||||
|
||||
use Illuminate\Contracts\Pagination\CursorPaginator;
|
||||
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
|
||||
{
|
||||
/**
|
||||
* 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;
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
@@ -6,9 +6,9 @@ class DataCollectableTransformer extends \Spatie\LaravelData\Transformers\DataCo
|
||||
{
|
||||
protected function wrapPaginatedArray(array $paginated): array
|
||||
{
|
||||
$wrapKey = $this->wrap->getKey() ?? 'data';
|
||||
|
||||
return [
|
||||
$wrapKey = $this->wrap->getKey() ?? 'data';
|
||||
|
||||
return [
|
||||
$wrapKey => $paginated['data'],
|
||||
'links' => [
|
||||
'first' => $paginated['first_page_url'],
|
||||
|
||||
@@ -6,18 +6,18 @@ 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();
|
||||
}
|
||||
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,8 +3,8 @@
|
||||
namespace App\DataTransferObjects\Support\Rules;
|
||||
|
||||
use Attribute;
|
||||
use Spatie\LaravelData\Attributes\Validation\CustomValidationAttribute;
|
||||
use Spatie\LaravelData\Support\Validation\ValidationPath;
|
||||
use Spatie\LaravelData\Attributes\Validation\CustomValidationAttribute;
|
||||
|
||||
#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)]
|
||||
class CustomRule extends CustomValidationAttribute
|
||||
@@ -22,7 +22,7 @@ class CustomRule extends CustomValidationAttribute
|
||||
public function getRules(ValidationPath $path): array|object|string
|
||||
{
|
||||
return array_map(
|
||||
fn(string $ruleClass) => new $ruleClass(),
|
||||
fn (string $ruleClass) => new $ruleClass(),
|
||||
$this->rules
|
||||
);
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ class CarbonTransformer implements Transformer
|
||||
{
|
||||
public function transform(DataProperty $property, mixed $value): string
|
||||
{
|
||||
/** @var Carbon $value */
|
||||
/** @var Carbon $value */
|
||||
return $value->toISOString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,15 +20,15 @@ class UserData extends Data
|
||||
public ?int $id = null,
|
||||
public ?string $avatar = null,
|
||||
#[StringType,
|
||||
Max(255)]
|
||||
Max(255)]
|
||||
public ?string $name = null,
|
||||
#[StringType,
|
||||
Email,
|
||||
Max(255),
|
||||
Unique(User::class)]
|
||||
Email,
|
||||
Max(255),
|
||||
Unique(User::class)]
|
||||
public ?string $email = null,
|
||||
#[Exists(Package::class, 'id'),
|
||||
IntegerType]
|
||||
IntegerType]
|
||||
public ?int $package_id = null,
|
||||
#[StringType]
|
||||
public ?string $blocked = null,
|
||||
|
||||
@@ -8,9 +8,9 @@ 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
|
||||
{
|
||||
|
||||
@@ -63,7 +63,7 @@ class UserResource extends Resource
|
||||
Forms\Components\Select::make('language')
|
||||
->label(__('Language'))
|
||||
->default('en')
|
||||
->options(collect(languages())->mapWithKeys(fn(string $language) => [$language => $language])),
|
||||
->options(collect(languages())->mapWithKeys(fn (string $language) => [$language => $language])),
|
||||
Forms\Components\Textarea::make('notes')
|
||||
->label(__('Notes'))
|
||||
->maxLength(65535),
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
|
||||
namespace App\Filament\Resources\UserResource\Pages;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use App\Filament\Resources\UserResource;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class CreateUser extends CreateRecord
|
||||
{
|
||||
|
||||
@@ -5,10 +5,10 @@ namespace App\Filament\Resources\UserResource\Pages;
|
||||
use Filament\Pages\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;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class EditUser extends EditRecord
|
||||
{
|
||||
|
||||
@@ -3,9 +3,7 @@
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Filament\Notifications\Notification;
|
||||
use Illuminate\Http\Request;
|
||||
use Livewire\Livewire;
|
||||
|
||||
class Demo
|
||||
{
|
||||
|
||||
136
config/data.php
136
config/data.php
@@ -3,71 +3,71 @@
|
||||
use App\DataTransferObjects;
|
||||
|
||||
return [
|
||||
/*
|
||||
* The package will use this format when working with dates. If this option
|
||||
* is an array, it will try to convert from the first format that works,
|
||||
* and will serialize dates using the first format from the array.
|
||||
*/
|
||||
'date_format' => DATE_ATOM,
|
||||
|
||||
/*
|
||||
* Global transformers will take complex types and transform them into simple
|
||||
* types.
|
||||
*/
|
||||
'transformers' => [
|
||||
DateTimeInterface::class => DataTransferObjects\Support\Transformers\CarbonTransformer::class,
|
||||
\Illuminate\Contracts\Support\Arrayable::class => \Spatie\LaravelData\Transformers\ArrayableTransformer::class,
|
||||
BackedEnum::class => Spatie\LaravelData\Transformers\EnumTransformer::class,
|
||||
],
|
||||
|
||||
/*
|
||||
* Global casts will cast values into complex types when creating a data
|
||||
* object from simple types.
|
||||
*/
|
||||
'casts' => [
|
||||
DateTimeInterface::class => DataTransferObjects\Support\Casts\CarbonCast::class,
|
||||
BackedEnum::class => Spatie\LaravelData\Casts\EnumCast::class,
|
||||
],
|
||||
|
||||
/*
|
||||
* Rule inferrers can be configured here. They will automatically add
|
||||
* validation rules to properties of a data object based upon
|
||||
* the type of the property.
|
||||
*/
|
||||
'rule_inferrers' => [
|
||||
Spatie\LaravelData\RuleInferrers\SometimesRuleInferrer::class,
|
||||
Spatie\LaravelData\RuleInferrers\NullableRuleInferrer::class,
|
||||
Spatie\LaravelData\RuleInferrers\RequiredRuleInferrer::class,
|
||||
Spatie\LaravelData\RuleInferrers\BuiltInTypesRuleInferrer::class,
|
||||
Spatie\LaravelData\RuleInferrers\AttributesRuleInferrer::class,
|
||||
],
|
||||
|
||||
/**
|
||||
* Normalizers return an array representation of the payload, or null if
|
||||
* it cannot normalize the payload. The normalizers below are used for
|
||||
* every data object, unless overridden in a specific data object class.
|
||||
*/
|
||||
'normalizers' => [
|
||||
Spatie\LaravelData\Normalizers\ModelNormalizer::class,
|
||||
// Spatie\LaravelData\Normalizers\FormRequestNormalizer::class,
|
||||
Spatie\LaravelData\Normalizers\ArrayableNormalizer::class,
|
||||
Spatie\LaravelData\Normalizers\ObjectNormalizer::class,
|
||||
Spatie\LaravelData\Normalizers\ArrayNormalizer::class,
|
||||
Spatie\LaravelData\Normalizers\JsonNormalizer::class,
|
||||
],
|
||||
|
||||
/*
|
||||
* Data objects can be wrapped into a key like 'data' when used as a resource,
|
||||
* this key can be set globally here for all data objects. You can pass in
|
||||
* `null` if you want to disable wrapping.
|
||||
*/
|
||||
'wrap' => null,
|
||||
|
||||
/**
|
||||
* Adds a specific caster to the Symphony VarDumper component which hides
|
||||
* some properties from data objects and collections when being dumped
|
||||
* by `dump` or `dd`. Can be 'enabled', 'disabled' or 'development'
|
||||
* which will only enable the caster locally.
|
||||
*/
|
||||
'var_dumper_caster_mode' => 'development',
|
||||
];
|
||||
/*
|
||||
* The package will use this format when working with dates. If this option
|
||||
* is an array, it will try to convert from the first format that works,
|
||||
* and will serialize dates using the first format from the array.
|
||||
*/
|
||||
'date_format' => DATE_ATOM,
|
||||
|
||||
/*
|
||||
* Global transformers will take complex types and transform them into simple
|
||||
* types.
|
||||
*/
|
||||
'transformers' => [
|
||||
DateTimeInterface::class => DataTransferObjects\Support\Transformers\CarbonTransformer::class,
|
||||
\Illuminate\Contracts\Support\Arrayable::class => \Spatie\LaravelData\Transformers\ArrayableTransformer::class,
|
||||
BackedEnum::class => Spatie\LaravelData\Transformers\EnumTransformer::class,
|
||||
],
|
||||
|
||||
/*
|
||||
* Global casts will cast values into complex types when creating a data
|
||||
* object from simple types.
|
||||
*/
|
||||
'casts' => [
|
||||
DateTimeInterface::class => DataTransferObjects\Support\Casts\CarbonCast::class,
|
||||
BackedEnum::class => Spatie\LaravelData\Casts\EnumCast::class,
|
||||
],
|
||||
|
||||
/*
|
||||
* Rule inferrers can be configured here. They will automatically add
|
||||
* validation rules to properties of a data object based upon
|
||||
* the type of the property.
|
||||
*/
|
||||
'rule_inferrers' => [
|
||||
Spatie\LaravelData\RuleInferrers\SometimesRuleInferrer::class,
|
||||
Spatie\LaravelData\RuleInferrers\NullableRuleInferrer::class,
|
||||
Spatie\LaravelData\RuleInferrers\RequiredRuleInferrer::class,
|
||||
Spatie\LaravelData\RuleInferrers\BuiltInTypesRuleInferrer::class,
|
||||
Spatie\LaravelData\RuleInferrers\AttributesRuleInferrer::class,
|
||||
],
|
||||
|
||||
/**
|
||||
* Normalizers return an array representation of the payload, or null if
|
||||
* it cannot normalize the payload. The normalizers below are used for
|
||||
* every data object, unless overridden in a specific data object class.
|
||||
*/
|
||||
'normalizers' => [
|
||||
Spatie\LaravelData\Normalizers\ModelNormalizer::class,
|
||||
// Spatie\LaravelData\Normalizers\FormRequestNormalizer::class,
|
||||
Spatie\LaravelData\Normalizers\ArrayableNormalizer::class,
|
||||
Spatie\LaravelData\Normalizers\ObjectNormalizer::class,
|
||||
Spatie\LaravelData\Normalizers\ArrayNormalizer::class,
|
||||
Spatie\LaravelData\Normalizers\JsonNormalizer::class,
|
||||
],
|
||||
|
||||
/*
|
||||
* Data objects can be wrapped into a key like 'data' when used as a resource,
|
||||
* this key can be set globally here for all data objects. You can pass in
|
||||
* `null` if you want to disable wrapping.
|
||||
*/
|
||||
'wrap' => null,
|
||||
|
||||
/**
|
||||
* Adds a specific caster to the Symphony VarDumper component which hides
|
||||
* some properties from data objects and collections when being dumped
|
||||
* by `dump` or `dd`. Can be 'enabled', 'disabled' or 'development'
|
||||
* which will only enable the caster locally.
|
||||
*/
|
||||
'var_dumper_caster_mode' => 'development',
|
||||
];
|
||||
|
||||
@@ -31,10 +31,10 @@ it('can list packages', function () {
|
||||
])
|
||||
->all(),
|
||||
'links' => [
|
||||
'first' => route('api.package.index', ['page' => 1]),
|
||||
'last' => route('api.package.index', ['page' => 2]),
|
||||
'prev' => null,
|
||||
'next' => route('api.package.index', ['page' => 2]),
|
||||
'first' => route('api.package.index', ['page' => 1]),
|
||||
'last' => route('api.package.index', ['page' => 2]),
|
||||
'prev' => null,
|
||||
'next' => route('api.package.index', ['page' => 2]),
|
||||
],
|
||||
'meta' => [
|
||||
'current_page' => 1,
|
||||
|
||||
Reference in New Issue
Block a user