Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

IN2SITES's avatar

Livewire not working

I have a contactform as a livewire component but it's not working on wire:model.

  1. in layouts/app.blade.php i have entered the directives @livewireStyles

I created a livewire component called contact-form: @extends('layouts.app') @section('content') livewire:contact-form/ @endsection

the component itself: it tested the input field with {{$name}} to see the binding in action but when i type there is no action

        <div class="form-floating mb-3">
            <span>{{ $name }}</span>
            <input wire:model="name" type="text" name="name" type="text" class="form-control" placeholder="Name" id="name">
            <label for="name">Name</label>
        </div>

        <div class="form-floating mb-3">
            <input wire:model="email" type="email" name="email" type="text" class="form-control" placeholder="E-mail" id="email">
            <label for="email">E-mail</label>
        </div>
        <div class="form-floating mb-3">
            <textarea wire:model="message" name="message" id="message" class="form-control" placeholder="leave a comment"
                      style="height:180px"></textarea>
            <label for="message">Comments</label>
        </div>
        <button type="submit" class="btn btn-dark d-flex justify-content-end">SUBMIT</button>
    </form>
</div>

The contactform is showing fine and the inspect element/console does not return any errors.

Any suggestions?

0 likes
3 replies
LaryAI's avatar
Level 58

It seems like you've done the initial setup correctly by including @livewireStyles in your layouts/app.blade.php. However, there are a few things we need to check to ensure Livewire is working properly.

  1. Make sure you have included @livewireScripts at the end of your layouts/app.blade.php file, just before the closing </body> tag. This is crucial for Livewire's JavaScript to work.
<!-- layouts/app.blade.php -->
...
@livewireScripts
</body>
  1. Ensure that you have published Livewire's assets and that they are accessible. You can publish Livewire's assets by running the following command:
php artisan livewire:publish --assets
  1. Verify that your Livewire component class (likely named ContactForm.php if your component is called contact-form) has the public properties $name, $email, and $message defined, as these are the properties you're trying to bind to in your view.
// App/Http/Livewire/ContactForm.php
namespace App\Http\Livewire;

use Livewire\Component;

class ContactForm extends Component
{
    public $name;
    public $email;
    public $message;

    public function render()
    {
        return view('livewire.contact-form');
    }
}
  1. Ensure that your Livewire component is correctly referenced in your Blade file. It should be used as a directive without the livewire: prefix or trailing slash. Also, make sure you are not using both Blade @extends and Livewire component directives in the same file. Your Blade file should look like this:
<!-- resources/views/livewire/contact-form.blade.php -->
@extends('layouts.app')

@section('content')
    <div>
        <!-- Your Livewire component's markup -->
        <form wire:submit.prevent="submit">
            <!-- Your form inputs and bindings -->
        </form>
    </div>
@endsection
  1. If you have a form, make sure you're preventing the default form submission with wire:submit.prevent on the form tag, and you have a method in your Livewire component to handle the submission.
// App/Http/Livewire/ContactForm.php
...
public function submit()
{
    // Handle form submission
}
  1. Clear your cache and view cache, as sometimes stale cache can cause issues with Livewire.
php artisan cache:clear
php artisan view:clear
  1. Check your browser's developer console for any JavaScript errors that might be preventing Livewire from initializing correctly.

If you've checked all these points and it's still not working, please provide more details about your Livewire component class and the Blade file where you're including the Livewire component. This will help in diagnosing the issue further.

IN2SITES's avatar

ok. when in run php artisan serve then livewire workst on the route given. But when i want to access local f.e. http::/localhost/myproject/public/ It does not work? Why is that?

Please or to participate in this conversation.