Reputation: 62
im newbie here, I have a simple question that keeps me up all night,so is it posible to double render in livewire like a normal controller?
like this
//Home Controller
public function index(){
return view(home.index);
}
public function dragonCat(){
return view(blah.index);
}
Upvotes: 0
Views: 601
Reputation: 2490
Not in the way that you're showing (using separate methods), no. And that's also not how Livewire is meant to work. However, if there's a reason why you would want that, perhaps I can give you a suggestion on a better approach.
Just for info, a controller is a bridge between your HTTP routes and your views. While you technically don't need a controller (as the routes you define just need a callback), you use a controller at first to keep things organized (e.g. all Product model related routes) as well as to define more complex logic that would otherwise clutter your web.php
.
A Livewire component is a "live" piece of frontend, a reactive component, basically a very complex and high quality AJAX wrapper to communicate between the client and the server. It uses DOM diffing to ensure minimal payload needed. If you were to change the view in the render method, maybe that would work, but it would most likely be very slow as it would mean replacing the whole view.
So where a controller "technically" has (or can have) more than one return view()
, you would always only ever call one at the same time, since it would be related to the current route you're on. A Livewire component can also only have one return view()
, however there is nothing bad about having more than one Livewire component on a single page.
Upvotes: 2