简体   繁体   中英

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

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!!

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM