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

allTenants Call to a member function newQueryWithoutTenants() on null #77

Open
rikvdlooi opened this issue Sep 26, 2017 · 2 comments
Open

Comments

@rikvdlooi
Copy link
Contributor

When calling ::allTenants() on a model that has not been booted I get the following error.

PHP error:  Call to a member function newQueryWithoutTenants() on null in vendor/hipsterjazzbo/landlord/src/BelongsToTenants.php

I found that this is due to that the Model has not yet booted (it was never instantiated). This means the bootBelongsToTenants() will never get called, so in turn $landlord will never be set to a TenantManager.

I'm using the newest version of LandLord with Laravel 5.5.

@rikvdlooi
Copy link
Contributor Author

I see a PR was created to fix this. Pull Request #75

@rikvdlooi
Copy link
Contributor Author

Workaround for people stumbling upon this: instantiate the model you want to call allTenants() on. Example:

use App\Books;

public function getAllBooks()
{
    // Workaround to call boot method, needed for Landlord to work correctly.
    new Books;
    
    return Books::allTenants()->get();
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant