Custom column to display a pivot of the current user and tenancy relationship
I would like to display a boolean column of the users and the currenty tenant relation in a table and I am a bit lost. Can someone point me to the right direction? Thanks
Solution:Jump to solution
With a bit of help from chatgpt:
User.php
```php
public function getAcceptedForCurrentTenantAttribute()...
3 Replies
Not sure what you mean by " a boolean column of the users and the currenty tenant relation". Can you explain exactly what you are trying to show?
I am using stancl/tenancy for a plateform with tenancy. Users create an account and ask permission to access a tenant. When they register, I attach the tenant to a user and save some variables to the pivot table. On of those columns is "accepted" with a default value of 0. In filament, the user resource displays all the users that have the relationship of the current tenant. I now would like to display true or false (if they have been accepted or not) in a column based on the value from the pivot.
I would like to do something like this $user->tenants()->where('id', $tenantId)->first(); and display the "accepted" column.
Currently if I do "tenants.id" all the ids of the attached tenants are displayed. "tenants.accepted" returns nothing, probably because there is not with() in the query.
My question is how to I add a custom query to a column?
Solution
With a bit of help from chatgpt:
User.php
UserResource.php
This seems to work