Skip to content

Commit

Permalink
Merge branch 'main' into beyond-data
Browse files Browse the repository at this point in the history
# Conflicts:
#	CHANGELOG.md
#	docs/advanced-usage/validation-attributes.md
#	src/Transformers/DataTransformer.php
  • Loading branch information
rubenvanassche committed Dec 1, 2023
2 parents c02fbfa + 41bba12 commit b57f99d
Show file tree
Hide file tree
Showing 16 changed files with 399 additions and 16 deletions.
22 changes: 21 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,26 @@ All notable changes to `laravel-data` will be documented in this file.
- Allow creating data objects using `from` without parameters
- Add support for a Dto and Resource object

## 3.10.0 - 2023-12-01

A fresh release after a month of vacation, enjoy!

- Add ExcludeWith validation rule (#584)
- Add DoesntEndWith and DoesntStartWith validation rules (#585)
- Add MinDigits and MaxDigits validation rules (#586)
- Add DataCollection reject() method (#593)
- Add generic type for WithData trait (#597)
- Fix issue where non set optional values were transformed (#602)
- Fix issue where parameters passed to Laravel Collection methods would sometimes provide alternative results (issue: #607)

## 1.5.3 - 2023-12-01

- MimeTypes validation fix on v1 (#596)

## 3.9.2 - 2023-10-20

- Fix breaking compatibility #590

## 3.9.1 - 2023-10-12

- Add Declined and DeclinedIf validation attributes (#572)
Expand Down Expand Up @@ -44,7 +64,7 @@ All notable changes to `laravel-data` will be documented in this file.

- fix target namespace when creating files with Laravel Idea (#497)
- allow collection to be created passing null (#507)
- add Ulid validation rule (#510)
- add Ulid validation rule (#510)
-add TARGET_PARAMETER to Attribute for improved Validation (#523)

## 3.7.0 - 2023-07-05
Expand Down
77 changes: 77 additions & 0 deletions docs/advanced-usage/validation-attributes.md
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,36 @@ public string $closure;
public string $closure;
```

## DoesntEndWith

[Docs](https://laravel.com/docs/9.x/validation#rule-doesnt-end-with)

```php
#[DoesntEndWith('a')]
public string $closure;

#[DoesntEndWith(['a', 'b'])]
public string $closure;

#[DoesntEndWith('a', 'b')]
public string $closure;
```

## DoesntStartWith

[Docs](https://laravel.com/docs/9.x/validation#rule-doesnt-start-with)

```php
#[DoesntStartWith('a')]
public string $closure;

#[DoesntStartWith(['a', 'b'])]
public string $closure;

#[DoesntStartWith('a', 'b')]
public string $closure;
```

## Email

[Docs](https://laravel.com/docs/9.x/validation#rule-email)
Expand Down Expand Up @@ -352,6 +382,17 @@ public string $closure;
public string $closure;
```

## ExcludeWith

*At the moment the data is not yet excluded due to technical reasons, v4 should fix this*

[Docs](https://laravel.com/docs/9.x/validation#rule-exclude-with)

```php
#[ExcludeWith('other_field')]
public string $closure;
```

## ExcludeWithout

*At the moment the data is not yet excluded due to technical reasons, v4 should fix this*
Expand Down Expand Up @@ -513,6 +554,15 @@ public int $closure;
public int $closure;
```

## Lowercase

[Docs](https://laravel.com/docs/9.x/validation#rule-lowercase)

```php
#[Lowercase]
public string $closure;
```

## MacAddress

[Docs](https://laravel.com/docs/9.x/validation#rule-mac)
Expand All @@ -531,6 +581,15 @@ public string $closure;
public int $closure;
```

## MaxDigits

[Docs](https://laravel.com/docs/9.x/validation#rule-max-digits)

```php
#[MaxDigits(10)]
public int $closure;
```

## MimeTypes

[Docs](https://laravel.com/docs/9.x/validation#rule-mimetypes)
Expand Down Expand Up @@ -570,6 +629,15 @@ public UploadedFile $closure;
public int $closure;
```

## MinDigits

[Docs](https://laravel.com/docs/9.x/validation#rule-min-digits)

```php
#[MinDigits(2)]
public int $closure;
```

## MultipleOf

[Docs](https://laravel.com/docs/9.x/validation#rule-multiple-of)
Expand Down Expand Up @@ -895,6 +963,15 @@ public string $closure;
public string $closure;
```

## Uppercase

[Docs](https://laravel.com/docs/9.x/validation#rule-uppercase)

```php
#[Uppercase]
public string $closure;
```

## Url

[Docs](https://laravel.com/docs/9.x/validation#rule-url)
Expand Down
28 changes: 28 additions & 0 deletions src/Attributes/Validation/DoesntEndWith.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace Spatie\LaravelData\Attributes\Validation;

use Attribute;
use Illuminate\Support\Arr;
use Spatie\LaravelData\Support\Validation\References\RouteParameterReference;

#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)]
class DoesntEndWith extends StringValidationAttribute
{
protected string|array $values;

public function __construct(string|array|RouteParameterReference ...$values)
{
$this->values = Arr::flatten($values);
}

public static function keyword(): string
{
return 'doesnt_end_with';
}

public function parameters(): array
{
return [$this->values];
}
}
28 changes: 28 additions & 0 deletions src/Attributes/Validation/DoesntStartWith.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace Spatie\LaravelData\Attributes\Validation;

use Attribute;
use Illuminate\Support\Arr;
use Spatie\LaravelData\Support\Validation\References\RouteParameterReference;

#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)]
class DoesntStartWith extends StringValidationAttribute
{
protected string|array $values;

public function __construct(string|array|RouteParameterReference ...$values)
{
$this->values = Arr::flatten($values);
}

public static function keyword(): string
{
return 'doesnt_start_with';
}

public function parameters(): array
{
return [$this->values];
}
}
28 changes: 28 additions & 0 deletions src/Attributes/Validation/ExcludeWith.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace Spatie\LaravelData\Attributes\Validation;

use Attribute;
use Spatie\LaravelData\Support\Validation\References\FieldReference;

#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)]
class ExcludeWith extends StringValidationAttribute
{
protected FieldReference $field;

public function __construct(
string|FieldReference $field,
) {
$this->field = $this->parseFieldReference($field);
}

public static function keyword(): string
{
return 'exclude_with';
}

public function parameters(): array
{
return [$this->field];
}
}
19 changes: 19 additions & 0 deletions src/Attributes/Validation/Lowercase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace Spatie\LaravelData\Attributes\Validation;

use Attribute;

#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)]
class Lowercase extends StringValidationAttribute
{
public static function keyword(): string
{
return 'lowercase';
}

public function parameters(): array
{
return [];
}
}
24 changes: 24 additions & 0 deletions src/Attributes/Validation/MaxDigits.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace Spatie\LaravelData\Attributes\Validation;

use Attribute;
use Spatie\LaravelData\Support\Validation\References\RouteParameterReference;

#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)]
class MaxDigits extends StringValidationAttribute
{
public function __construct(protected int|RouteParameterReference $value)
{
}

public static function keyword(): string
{
return 'max_digits';
}

public function parameters(): array
{
return [$this->value];
}
}
24 changes: 24 additions & 0 deletions src/Attributes/Validation/MinDigits.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace Spatie\LaravelData\Attributes\Validation;

use Attribute;
use Spatie\LaravelData\Support\Validation\References\RouteParameterReference;

#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)]
class MinDigits extends StringValidationAttribute
{
public function __construct(protected int|RouteParameterReference $value)
{
}

public static function keyword(): string
{
return 'min_digits';
}

public function parameters(): array
{
return [$this->value];
}
}
19 changes: 19 additions & 0 deletions src/Attributes/Validation/Uppercase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace Spatie\LaravelData\Attributes\Validation;

use Attribute;

#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)]
class Uppercase extends StringValidationAttribute
{
public static function keyword(): string
{
return 'uppercase';
}

public function parameters(): array
{
return [];
}
}
Loading

0 comments on commit b57f99d

Please sign in to comment.