Going deeper on Tenant relationships
I'm trying to create a resource for a child of a resource that belongs to my tenant. But since the child resource doesn't have a direct relation to the tenant, when I try to view the list page, I'm getting an error as such. I'm likely missing something obvious, and don't know if this is a Filament question or general Laravel question.
The error message:
Button BelongsTo ButtonGroup
ButtonGroup BelongsTo Agency
Agency is my Tenant
I have tried and failed to add an function into my Button model, but can't get one to work.
Solution:Jump to solution
I found this closed Issue (https://github.com/filamentphp/filament/issues/8468), which references the . Looked it up and installed the package. I have gotten past my errors.
10 Replies
for clarity. I've created the resource, just when I click on it to go to the list in my panel, I get the above error message.
I notice that the error message you quoted refers to a relationship named
[agency]
but you said you created agencies(): BelongsTo
.
What does the "Button" model refer to? (ie: why is it named Button?)the "Button" model is equivalent to a post in this instance. It's named Button since I'm writing this webapp as a supplemental tool for another product, and that's what the other tool calls this piece.
I did make a mistake in my original post and I did create updated the origial question.
I'm trying something along these lines, but it isn't working:
Oh. That's not how Laravel BelongsTo works. Wrong syntax.
I think i have gathered that that's where I was going wrong
Here's a thread where I explained a bunch about Laravel Relations including some syntax: https://discord.com/channels/883083792112300104/1160724944922103959/1160737635631902810
So do I need to directly relate my Buttons to my Agencies with BelongsTo and HasMany? I can't do anything to automatically go through the middle relation? (ButtonGroup)
Laravel has a HasManyThrough (and maybe BelongsToManyThrough?) relationship, which I believe Filament supports.
We're getting closer. I found HasManyThrough which I put on my Agency to have many Buttons through ButtonGroups. but I do not see anything like BelongsToThrough. I tried HasOneThrough, but that's backward since my ButtonGroups doesn't have a button_id column (since it's one to many in the other direction)
Solution
I found this closed Issue (https://github.com/filamentphp/filament/issues/8468), which references the . Looked it up and installed the package. I have gotten past my errors.