Skip to content
Advertisement

Laravel Livewire – Best way to use [closed]

I have been interested in Laravel Livewire for a few days. But I wonder what is the best way to use it?

I have a website built on controllers. I would now like to add a forum in Livewire.

  1. Should I build a forum traditionally on controllers, and add livewire components to the view to display categories, topics, messages? Does it miss the point and better to skip traditional controllers?

  2. How to name livewire components?

  • livewire/forum/index.blade.php
  • livewire/forum/topics/index.blade.php

//

  • livewire/showForums.blade.php
  • livewire/showForumTopics.blade.php

I want to stick to some naming convention because as the project grows I don’t want it to look chaotic. I will have many more livewire components in the future.

Advertisement

Answer

I’m putting this here as it was too long for a comment.

The point of Livewire is to lower the knowledge requirement for creating interactive interfaces, specifically without having to leave the comfort of Laravel. How you choose to implemenent your project (i.e. the choice between full page compoents and single components) is down to you based on the use case. I wouldn’t use a full page component if I only wanted to make a single page element interactive.

In your example, you could use either. However, a full page component might make more sense as you will remove the requirement to fire off events to have other components update themselves.

Try and adhere to existing Laravel naming conventions if possible, but most importantly – be consistent with your naming!

I try to keep my components and views in sync with each other, which is also the recommendation on the Livewire documentation.

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

Take a look at the building a voting app with Livewire series on Laracasts. It might help with your decision making.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement