F
Filament9mo ago
Kyle

Get ID of parent model when making a child model using Relationship Manager via the modal

For example, when I am using a relationship manager to show the students inside a class. And the form editor for the class is currently showing the class edit form, and the students are shown in a table at the bottom of the page. There is a button in the table to create a new student, which will show a modal for creating the student. Fortunately, the class_id is automatically set when saving the student model, but I need the class_id for a different purpose. How do I get the parent class model (or at least its id property) so that I can use it in the dependency-injected functions? Thank you very much in advance.
2 Replies
gladjanus43
gladjanus439mo ago
$livewire->ownerRecord gives the parent record from the relationmanager
Kyle
KyleOP2mo ago
Thank you very much! I'll try that. For other people's reference, the correct code is $this->ownerRecord. You will get the actual Model, so you might need to use $this->ownerRecord->id to get the id or any other attribute of your model.

Did you find this page helpful?