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

TobiasS's avatar
Level 10

Naming components

Hi!

I'm new to Livewire and need help with naming components?

From Livewire documentation

php artisan make:livewire post.show

creates

app/Http/Livewire/Post/Show.php
resources/views/livewire/post/show.blade.php

in web.php I can now use

use App\Http\Livewire\Posts\Show;
Route::get('/posts/{post}', Show::class);

But what about when I want to create comments

```
php artisan make:livewire comments.show

in web.php the show class is already taken?

what is the best way to solve this? change naming conventions? I'm grateful for all advice!

Best regards, Tobias

0 likes
12 replies
tykus's avatar

You can either fully-qualify the class name

Route::get('/posts/{post}', \App\Http\Livewire\Post\Show::class);
Route::get('/categories/{categories}', \App\Http\Livewire\Category\Show::class);

or, alias a different name

use App\Http\Livewire\Post\Show as PostShow;
use App\Http\Livewire\Category\Show as CategoryShow;
// ...
Route::get('/posts/{post}', PostShow::class);
Route::get('/categories/{categories}', CategoryShow::class);
TobiasS's avatar
Level 10

Thx for the fast replies!

With normal controllers I find it easy to know what to name the files. With Livewire I’m not sure if it is wisest to name it PostShow, PostIndex, PostCreate and CommentShow, CommentIndex etc

Or posts\show, posts\index etc

Any thoughts?

tykus's avatar

Where do you get benefits from replacing entire Controller actions with Livewire components? Are the view so dynamic???

If this is something you really need; then namespacing the Livewire components appropriately (as you are) should not be an issue - just follow the approach I described in the previous reply

TobiasS's avatar
Level 10

Thx!

No, not all views are that dynamic. Just wanted to check how it works building without using controllers and just livewire.

martinbean's avatar

Then again the question I would ask is… “Why?”

Use Livewire if you need Livewire functionality. Not just as a general purpose controller replacement.

tykus's avatar

In my honest opinion, this is overkill. A Livewire component for small units of dynamic markup within regular view templates is just enough

TobiasS's avatar
Level 10

Thx again!

Just wanted to check if/how it would work to skip controllers. So I can not answer “Why?…” just curious.

tykus's avatar

Nothing wrong with scratching an itch. 😂

webrobert's avatar

@tobiass, I think it depends. And the naming from some of the tutorials seems silly, PostShow. I do some folding when necessary as mentioned above. BUT when using phpStorm searching for files named index sucks... I haven't flushed out naming entirely.

@tykus, overkill, for me it really depends. Take Caleb's example of an index of users with a search filter and modals to add and edit. It's pointless to have a controller too. The whole page is basically just a filter and list. Overkill is having a controller that just points to a view that just asks for a livewire component. The livewire component can replace the controller. It already has all the methods you'd find in the controller.

vs an autocomplete component.

For me, their naming creates confusion... "Livewire Component" because they are completely capable of being both a Component and a Controller.

tykus's avatar

@webrobert overkill was in the context of every Controller action mapping over to a Livewire component. You have isolated a very narrow example of an Index view

Please or to participate in this conversation.