Hi @toxifiedm
Is there a reason why you want to build this as a single Livewire component? Wouldn't it be easier to make it as two separate components?
Regards.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I am binding directly to the model property. I am unable to submit the form as there are two forms in a single livewire component. 1st form is to edit the user, which consist of name, email, role, and the 2nd form is to invite the user, which consist of email.
I am unable to submit the form as I have combinedly stated the rules for both the forms under the rules protected property. So when ever I try to edit a user, using the first form, It checks for email field as well, which is present in the invitation form. How can I make it work in this structure.
public $showUserManagementModal = false;
public $showUserInvitationModal = false;
public User $user;
public Invitation $invitation;
protected function rules() {
if ($showUserManagementModal = true)
return [
'user.name' => 'required | string | max:255',
'user.email' => 'required | string | email | max:255',
'role' => 'required',
];
if ($showUserInvitationModal = true)
return [
'invitation.email' => 'required | string | email | max:255 | unique:invitations,email',
];
}
public function createInvitation() {
$this -> useCachedRows();
$this -> resetValidation();
$this -> invitation = new Invitation();
$this -> showUserInvitationModal = true;
}
public function saveInvitation() {
$this -> validate();
$this -> invitation -> generateInvitationToken();
$this -> invitation -> save();
$this -> showUserInvitationModal = false;
}
public function manageUser(User $user) {
$this -> useCachedRows();
$this -> resetValidation();
$this -> user = $user;
$this -> role = $user -> roles -> pluck('id');
$this -> showUserManagementModal = true;
}
public function saveUser() {
$this -> validate();
$this -> validate([
'user.email' => 'unique:users,email,'.$this -> user -> id,
]);
$this -> user -> roles() -> sync($this -> role);
$this -> user -> save();
$this -> showUserManagementModal = false;
$this -> dispatchBrowserEvent('notify', $this -> user -> name.' Updated Successfully');
}
There are two issues with your rules() method - one being that I'm checking for a local variable (its not checking a property of the class) and secondly I'm assigning values to the variable instead of comparing (single = instead of double ==).
protected function rules() {
if ($this->showUserManagementModal === true)
return [
'user.name' => 'required|string|max:255',
'user.email' => 'required|string|email|max:255',
'role' => 'required',
];
if ($this->showUserInvitationModal === true)
return [
'invitation.email' => 'required|string|email|max:255|unique:invitations,email',
];
}
Please or to participate in this conversation.