-
Can someone please point me in the right direction? I am unable to find a solution in the docs or here in the issues section. What is the best method for passing the validation rules to my Livewire component class?
My UserData DTO: class UserData extends Data implements Wireable
{
use WireableData;
public function __construct(
public string $id,
public string $name,
public string $email,
) {}
public static function rules()
{
return [
'name' => ['required', 'string', 'max:255'],
'email' => ['required', 'string', 'email', 'max:255', 'unique:users,email'],
];
}
} My Livewire Class: class UpdateUserProfileInformationForm extends component
{
public UserData $user;
protected array $rules = [];
public function mount(string $id)
{
$this->user = UserData::from(User::where('id', $id)->firstOrFail());
$this->rules = $this->user->rules();
}
public function render()
{
return view('user.profile.update-user-profile-information-form');
}
public function updated($propertyName)
{
$this->validateOnly($propertyName);
}
public function submit()
{
$this->validate();
}
} |
Beta Was this translation helpful? Give feedback.
Answered by
gregupton
Dec 19, 2022
Replies: 1 comment 3 replies
-
I see this has been answered in discussions: |
Beta Was this translation helpful? Give feedback.
3 replies
Answer selected by
gregupton
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I see this has been answered in discussions:
https://github.com/spatie/laravel-data/discussions/274