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

lozadakb's avatar

Livewire: Unable to find component

I am trying to implement livewire in my application, created a first component to see if it works but I only got Unable to find component error.

My project is in laravel sail

Used the documentation instalation process and created a the first component

php artisan make:livewire counter

This created this componet in app/Http/Livewire

<?php

namespace Http\Livewire;

use Livewire\Component;

class Counter extends Component
{
    public function render()
    {
        return view('livewire.counter');
    }
}

And This view in resources/views/livewire

<div>
    <h1>Hi</h1>
</div>

I have tried @livewire('counter') and <livewire:counter /> to render

What have I tried or modified

  • On the very first componet created I notice that it was creating the component in app/App/Http/Liveware so I modify the config file
'class_namespace' => 'App\Http\Livewire'  changed to  'class_namespace' => 'Http\Livewire'

This modification created the components in app/Http/Livewire where the documentation says it should be but the error keep appearing.

0 likes
12 replies
Sinnbeck's avatar

Your class has the wrong namespace

namespace App\Http\Livewire;

And change it back in the config file

2 likes
lozadakb's avatar

@Sinnbeck make this to changes but is not working either

Changed namespace Http\Livewire; to namespace App\Http\Livewire;

Changed the config back to the original

'class_namespace' => 'Http\Livewire' to 'class_namespace' => 'App\Http\Livewire'

Using ths config created the components in

CLASS: app/App/Http/Livewire/Counter.php
VIEW:  resources/views/livewire/counter.blade.php

The view is fine, but I do not understand why the class is created in app/App

1 like
tykus's avatar

@lozadakb the file should be in the correct directory also - App\Http\Livewire means the path to the class should be app/Http/Livewire/Counter.php

1 like
tykus's avatar

Make sure that the component class file is being created in the correct directory that matches whatever namespace you are using - this is required for PSR-4 autoloading locate the class. Currently, the root namespace Http is probably not referenced in composer.json, so the class cannot be located.

1 like
lozadakb's avatar

@tykus this is the autoload config in composer.json

"autoload": {
        "psr-4": {
            "Vanguard\": "app/",
            "Database\Factories\": "database/factories/",
            "Database\Seeders\": "database/seeders/"
        }
    },

Could you tell me how can I make the reference?

Sinnbeck's avatar
Sinnbeck
Best Answer
Level 102

@lozadakb Vanguard? Any reason you changed it from app?

Then it's

namespace Vanguard\Http\Livewire;

same in config

1 like
tykus's avatar

@lozadakb FFS... don't you think your custom namespace was important to mention?

3 likes
lozadakb's avatar

@tykus I didn't know I had a custom namespace, if it wasn't for you I would not even notice, thanks again guys.

Please or to participate in this conversation.