Skip to content
This repository has been archived by the owner on Apr 11, 2024. It is now read-only.

Commit

Permalink
Add getType
Browse files Browse the repository at this point in the history
  • Loading branch information
francoism90 committed Mar 28, 2024
1 parent b5203da commit be7fb75
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/Forms/Concerns/WithForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,19 @@
namespace Foxws\LivewireUse\Forms\Concerns;

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

trait WithForm
{
protected function getType(string $property): string
{
$instance = new ReflectionProperty(static::class, $property);

return $instance->getType()->getName();
}

protected function collect(...$properties): Collection
{
return $properties
Expand Down Expand Up @@ -41,11 +50,24 @@ public function contains(string $property, mixed $args): bool
return $propertyValue === $args;
}

public function startsWith(string $property, mixed $needles = null): bool
public function startsWith(string $property, ...$needles): bool
{
if ($this->getType($property) !== 'string') {
return false;
}

return str($this->get($property, ''))->startsWith($needles);
}

public function after(string $property, string $search = null): ?Stringable
{
if ($this->getType($property) !== 'string') {
return null;
}

return str($this->get($property, ''))->after($search);
}

public function is(string $property, mixed $args = null): bool
{
return $this->get($property) == $args;
Expand Down

0 comments on commit be7fb75

Please sign in to comment.