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

Add CurrentTenant class that can be resolved from container #2

Closed
wants to merge 2 commits into from

Conversation

AlexVanderbist
Copy link
Member

Allows for things like this:

use Spatie\Multitenancy\Models\Contracts\CurrentTenant;

Route::get('/current-tenant', function (CurrentTenant $currentTenant) {
    return $currentTenant; // returns the current Tenant model
});

Copy link
Member

@freekmurze freekmurze left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking very good, thanks!

Just one question.

```php
use Spatie\Multitenancy\Models\Contracts\CurrentTenant;

Route::get('/current-tenant', function (CurrentTenant $currentTenant) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if there is no current tenant?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, currently it'll new up a new Tenant instance but I'll change it to be null

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, same issue exists for the currentTenant. I'll make both null

@AlexVanderbist
Copy link
Member Author

Too many issues:

  • wanted to throw an exception when resolving a currentTenant when there is no current tenant
  • can't hook into resolving a key that doesn't exist in the container
  • laravel will automatically create a new Tenant when trying to resolve CurrentTenant::class, even though it's literally bound to null 😠

Gonna close this for now due to the above issues.

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

Successfully merging this pull request may close these issues.

2 participants