Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Cannot Get Correct Tenant On Custom Multitenancy RelationShip #80

Open
OccTherapist opened this issue Sep 19, 2024 · 4 comments
Open
Assignees
Labels
bug Something isn't working

Comments

@OccTherapist
Copy link

OccTherapist commented Sep 19, 2024

What happened?

When using an other user tenant relationship than teams it throws this error:

Call to a member function newCollection() on null

When I change the global scope on the teams model to my custom relationship it works.

A generic solution would be nice.

How to reproduce the bug

Use a custom user tenant relationship e.g. belognsToMany facilities and try to open EmailResource.

Package Version

1.6.2

PHP Version

8.3

Laravel Version

11.22.0

Which operating systems does with happen with?

Linux

Notes

No response

@OccTherapist OccTherapist added the bug Something isn't working label Sep 19, 2024
@marcogermani87 marcogermani87 self-assigned this Sep 21, 2024
@marcogermani87
Copy link
Collaborator

Hi @OccTherapist, thanks for reporting! You can share User and Team models?

@OccTherapist
Copy link
Author

OccTherapist commented Sep 22, 2024

Here is the user models relationship:

public function facilities(): \Illuminate\Database\Eloquent\Relations\BelongsToMany
{
     return $this->belongsToMany(Facility::class, 'facility_user', 'user_id', 'facility_id');
}

And here is my tenants model relationship:

public function users(): \Illuminate\Database\Eloquent\Relations\BelongsToMany
{
    return $this->belongsToMany(User::class);
}

@marcogermani87
Copy link
Collaborator

marcogermani87 commented Sep 22, 2024

Take a look to the demo project: https://github.com/marcogermani87/filament-email-demo

Try to change Team method users() to:

public function members(): BelongsToMany
{
    return $this->belongsToMany(User::class);
}

Team model must have members() method: https://filamentphp.com/docs/3.x/panels/tenancy#adding-a-tenant-registration-page

@OccTherapist
Copy link
Author

Thats okay,

I also had to extend your Email Model

<?php

namespace App\Models;

use RickDBCN\FilamentEmail\Models\Email as BaseEmail;

class Email extends BaseEmail
{
    public function facility(): \Illuminate\Database\Eloquent\Relations\BelongsTo
    {
        return $this->belongsTo(Facility::class, 'team_id');
    }
}

But it shows no sent Emails in the Resource. In the database there is no team_id attached on the filament_email_log table for the entries.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants