Access resource record/model in custom component registered via registerRenderHook
What I am trying to do: I want to use custom livewire component (to use form builder) and register it with hook at position to a certain resource scope.
What I did: I've created livewire component, registered it. Everything works fine, component gets rendered in position I've provided.
My issue: Although everything renders fine, I want to use my resource(in which component is rendered) record. I can't find way to get my current resource page record. Is it possible to get current record of resource (if it is edit page) in custom livewire component ?
2 Replies
Only way I found to get current edit resource record ID (assuming that I hooked this component to certain Model) is like this:
Is there any other way to get record, or only this one ?
@Andrius I was running into this issue today too, and I tried putting the
registerRenderHook
in a Middleware instead of a Service provider.
I guess you could probably still do this through a service provider, but it wouldn't be as clean...
Then in the Custom Middleware handle()
method I run my checks for where to add the RenderHook (kind of like using the scopes:
method parameter),
Then in my Livewire component I have a class property which gets populated with the parameter in the @livewire(...)
string from the blade component