-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allows to specify rules as closure (#71)
- Loading branch information
1 parent
29abe7f
commit 22b1592
Showing
7 changed files
with
107 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
...dataset__component_with_rules_blade_php______tests_Feature_resources_view___de_php__.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
use Livewire\Volt\Actions; | ||
use Livewire\Volt\CompileContext; | ||
use Livewire\Volt\Contracts\Compiled; | ||
use Livewire\Volt\Component; | ||
|
||
new class extends Component implements Livewire\Volt\Contracts\FunctionalComponent | ||
{ | ||
public static CompileContext $__context; | ||
|
||
use Illuminate\Foundation\Auth\Access\AuthorizesRequests; | ||
|
||
public $title; | ||
|
||
public function mount() | ||
{ | ||
(new Actions\InitializeState)->execute(static::$__context, $this, get_defined_vars()); | ||
|
||
(new Actions\CallHook('mount'))->execute(static::$__context, $this, get_defined_vars()); | ||
} | ||
|
||
public function save() | ||
{ | ||
$arguments = [static::$__context, $this, func_get_args()]; | ||
|
||
return (new Actions\CallMethod('save'))->execute(...$arguments); | ||
} | ||
|
||
protected function rules() | ||
{ | ||
return (new Actions\ReturnRules)->execute(static::$__context, $this, []); | ||
} | ||
|
||
protected function messages() | ||
{ | ||
return (new Actions\ReturnValidationMessages)->execute(static::$__context, $this, []); | ||
} | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
tests/Feature/resources/views/functional-api/component-with-rules.blade.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
use function Livewire\Volt\{state, rules}; | ||
state(['title' => '']); | ||
rules(fn () => ['title' => ['required', 'min:5']]) | ||
->messages(['title' => 'The title field is missing.']); | ||
$save = function () { | ||
$this->validate(); | ||
$this->saved = true; | ||
}; ?> | ||
|
||
<div> | ||
<form wire:submit="save"> | ||
<input type="text" wire:model="title"> | ||
@error('title') <span class="error">{{ $message }}</span> @enderror | ||
|
||
<button type="submit">Save</button> | ||
</form> | ||
</div> | ||
|
||
|