How to access current model in custom view page
I made a livewire component and included it in a view page, but how can I access the current model in order to show the related data ?
Basically I want to make table of the relation with links to edit that relation, but to keep the edit page clean I dont want to include a relation manager there.
3 Replies
passing the id via parameter?
https://laravel-livewire.com/docs/2.x/rendering-components#parameters
Livewire
Rendering Components | Livewire
A full-stack framework for Laravel that takes the pain out of building dynamic UIs.
Define . You can access it with $this->recordd than.
Just tried, but its null :/ I am guessing it gets lost somewhere along the way.
ApartmentResource has a view route : 'view' => Pages\ViewApartment::route('/{record}'),
That route includes the component : @livewire('View-apartment')
That component shows the table : {{ $this->table }}
Which is defied in the livewire component
🫣
So I am thinking that the first view that calls the @livewire needs to forward the param ?
It works \o/ thanks both.
@livewire('View-apartment', ['record'=>$record])
public ?\App\Models\Apartment $record = null;