How do I use the same render in 2 separate view functions using the if route is condition? (Laravel/Livewire)

Viewed 192

How do I use the same render in 2 separate view functions using the if route is condition? (Laravel/Livewire)??

I want to render 2 different Livewire.view in the render function by checking the route is same to current route, something like that:

public function render()
{
   if (\Route::named('admin-appointments')) {
      return view('livewire.admin-appointments', [
      'data' => $this->read(),
      ]);
   }
   else{
      return view('livewire.user-appointments', [
      'data' => $this->read(),
      ]);
   }
}

but I have alwayse problem!!

1 Answers

Making the render depending on the route is unlikely to work. The first request will have the correct route, but all following requests will be triggered by Livewire and not match your route anymore. Instead, you need set a flag while mounting the Livewire component and make your rendering depending on this.

Related