Laravel form submit not working (Livewire + Turbolinks)

1.7k views Asked by At

I needed for my project the livewire package in, but have not used before. Some livewire components do not work without refreshing the page, i did not understand the reason for this.

<form wire:submit.prevent="login_method">
    <input type="text" wire:model="login.email" id="email">
    <input type="password" wire:model="login.password" id="password">
    <button type="submit">Login</button>
</form>
class Login extends Component
{
    public $login;

    public function login()
    {
        return dd($this->$login);
    }
    
    public function render()
    {
        return view('livewire.auth.login')->extends('layout.default');
    }
}

Note: I use Turbolinks (SPA). To switch between pages without refreshing the browser.

When I disable Turbolinks, form submission works, but when Turbolinks is active, livewire components are loaded when switching between pages, but the actions do not work.

Laravel 8.12 / Livewire 2.3 / Turbolinks 5.2

1

There are 1 answers

0
Fahad Ahmed On

Please change the method name in form tag from login_method to login as show in code below.

<form wire:submit.prevent="login">
    <input type="text" wire:model="login.email" id="email">
    <input type="password" wire:model="login.password" id="password">
    <button type="submit">Login</button>
</form>