There are many questions like this, but none explain more than “use only Livewire components” or “use Livewire only for interactivity.” Also, I cant find live code bases of real world web apps to see what is a good practice.
Approach 1: Using only components without controllers
Problems:
- The code will be so unorganized you will use them as controllers and also for some interactivity, it’s a mess.
- For some basic stuff, it’s convenient, but if you need to implement social login where you don’t even need a view and need a callback and redirect route, it’s ridiculous to use components. There are probably more things like this or more complex stuff where it’s so much easier to do it with a controller and use the normal routes.
Approach 2: Using components only for interactive stuff
Problems:
- If I want to have a form with live validation, I need to use a Livewire component, and so the entire create and update methods that would be in the controller will be put in a component, making the code unorganized because I will have delete and read method in controllers and create and update in components. This is just the first thing that came to my mind; probably there are more situations like this.
Questions:
What is a better approach and how do you go about the problems that I have for that approach?
Approach 1 solution:
- No solution that I know of. Maybe make 2 directories, name them something like Logic and UI, but then I will need controllers for complex stuff or things like social login, so I start using controllers and the code becomes a mess because I have controller logic in controllers and also in components.
Approach 2 solution:
- Maybe do validation and send data to the controller. I don’t know if this is even a good practice and can’t find anything online on how to do it.