Skip to content

Commit

Permalink
Add toFluent
Browse files Browse the repository at this point in the history
  • Loading branch information
francoism90 committed Apr 14, 2024
1 parent e6fda6a commit 0c6c898
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ php artisan vendor:publish --tag="wireuse-config"

You will find full documentation on the dedicated [documentation](https://foxws.nl/projects/wireuse) site.

> NOTE: The documentation is far from complete, see [this discussion](https://github.com/foxws/wireuse/discussions/3) for progress.
## Testing

```bash
Expand Down
20 changes: 14 additions & 6 deletions src/Forms/Concerns/WithForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Foxws\WireUse\Forms\Concerns;

use Illuminate\Support\Collection;
use Illuminate\Support\Fluent;
use Illuminate\Validation\ValidationException;
use ReflectionProperty;

Expand All @@ -15,11 +16,18 @@ protected function getType(string $property): string
return $instance->getType()->getName();
}

protected function collect(...$properties): Collection
protected function toCollection(...$properties): Collection
{
return $properties
? collect($this->only(...$properties))
: collect($this->all());
? new Collection($this->only(...$properties))
: new Collection($this->all());
}

protected function toFluent(...$properties): Fluent
{
return $properties
? new Fluent($this->only(...$properties))
: new Fluent($this->all());
}

protected function keys(): array
Expand All @@ -34,7 +42,7 @@ public function get(string $property, mixed $default = null): mixed

public function has(...$properties): bool
{
return $this->collect()
return $this->toCollection()
->has($properties);
}

Expand All @@ -61,14 +69,14 @@ public function isStrict(string $property, mixed $args = null): bool

public function filled(...$properties): bool
{
return $this->collect($properties)
return $this->toCollection($properties)
->filter()
->isNotEmpty();
}

public function blank(...$properties): bool
{
return $this->collect($properties)
return $this->toCollection($properties)
->filter()
->isEmpty();
}
Expand Down

0 comments on commit 0c6c898

Please sign in to comment.