PLATFORM
  • Tails

    Create websites with TailwindCSS

  • Blocks

    Design blocks for your website

  • Wave

    Start building the next great SAAS

  • Pines

    Alpine & Tailwind UI Library

  • Auth

    Plug'n Play Authentication for Laravel

  • Designer comingsoon

    Create website designs with AI

  • DevBlog comingsoon

    Blog platform for developers

  • Static

    Build a simple static website

  • SaaS Adventure

    21-day program to build a SAAS

Question By
Unsolved

Adding multiple inputs to db with livewire

manymangames

Aug 6th, 2021 01:49 AM

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.

bobbyiliev

Aug 6th, 2021 04:39 AM

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