Adding multiple inputs to db with livewire
Hello! I recently watched the tallstack theme video on youtube, where you are also adding data to database and render it on page. I started trying adding multiple input areas and multiple inputs to database with one button, but anytime I try always 500 error. So obviously I fail something hard. My goal is like, name, surname, date, age. 4 input boxes for each, but 1 button for all. When pressed button, like in the tutorial video, except it'll add everything to relevant columns in the table. If you guys can give me some tips how to achieve it I'd be appreciate it a lot.
Hello,
There should be no restrictions on how many fields are updated, I would recommend checking your Laravel error log to see the actual error rather than the generic 500 error.
Usually the update method could look like this:
public function update()
{
$this->validate([
'name' => 'required|min:5',
'email' => 'required|email:rfc'
]);
if ($this->user_id) {
$user = User::find($this->id);
$user->update([
'name' => $this->name,
'email' => $this->email
]);
}
}
In the example we check if we have a user id, and we update the email and the name at the same time with the new values from the form.
Let me know how it goes!
Regards,
Bobby