Home > Software engineering >  submit prevent doesn't work laravel livewire
submit prevent doesn't work laravel livewire

Time:12-11

i am doing tutorials doing comments website, i have app layout which yield content and register page the view is working fine but the form in register submit prevent doesnt work it just refresh when submitted.

here are the codes layout app blade php

 
`--``

<!DOCTYPE html>
<html lang="en">
<head>

    ...

    
    @livewireStyles
    @livewireScripts

    <script src="{{asset('js/app.js')}}"></script>

</head>

<body >

    <div >
        <a  href="/">Home</a>
        <div >
            <a  href="/login">Login</a>
            <a  href="/register">Register</a>
        </div>
    </div>
    <div >
        @yield('content')
    </div>

    
    
    <script src="https://cdn.jsdelivr.net/gh/livewire/[email protected]/dist/livewire-turbolinks.js" data-turbolinks-eval="false"></script>
    <script type="module">
        import hotwiredTurbo from 'https://cdn.skypack.dev/@hotwired/turbo';
    </script>
</body>

</html>


register blade php

@section('content')

<div >
    <section >
        <h1 >SignUp to Get Started</h1>
        <hr>
        <form  wire:submit.prevent="submit">
            <div >
                <div >
                    <input type="name"  wire:model="form.name"
                        placeholder="Name" />
                    @error('form.name') <span >{{ $message }}</span> @enderror
                </div>
            </div>

            <div >
                <div >
                    <input type="email"  placeholder="Email"
                        wire:model="form.email" />
                    @error('form.email') <span >{{ $message }}</span> @enderror
                </div>
            </div>

            <div >
                <div >
                    <input type="password"  placeholder="Password"
                        wire:model="form.password" />
                    @error('form.password') <span >{{ $message }}</span> @enderror
                </div>
            </div>

            <div >
                <div >
                    <input type="text"  
                        placeholder="Confirm Password" wire:model="form.password_confirmation" />
                </div>
            </div>
            
            <div >
                <div >
                    <input type="submit" value="Register"  />
                </div>
            </div>
        </form>
    </section>
</div>

@endsection

this is my first time posting, i searched in a lot of places but didnt find the solution.

it worked when i used @livewire('register') in app layout but if i use that the register page is visible in all other pages when app layout is called

CodePudding user response:

I found the solution, The problem was i am using the livewire 1.0 code which is '@yield('content')' in app layout, i changed that to '{{ $slot }}' and removed '@section('content')' blade code from my views it worked fine Check the documentation https://laravel-livewire.com/docs/2.x/upgrading#route-livewire

  • Related