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

PHP 8.1: Deprecation notice Accessing static trait property ($tenantIdColumn) #854

Closed
oscar-ol opened this issue Apr 29, 2022 · 10 comments
Closed
Labels

Comments

@oscar-ol
Copy link

oscar-ol commented Apr 29, 2022

Bug description

I'm getting this deprecation notice (PHP 8.1):

PHP Deprecated: Accessing static trait property Stancl\Tenancy\Database\Concerns\BelongsToTenant::$tenantIdColumn is deprecated, it should only be accessed on a class using the trait in /var/www/html/vendor/stancl/tenancy/src/Database/TenantScope.php on line 20
PHP Deprecated: Accessing static trait property Stancl\Tenancy\Database\Concerns\BelongsToTenant::$tenantIdColumn is deprecated, it should only be accessed on a class using the trait in /var/www/html/vendor/stancl/tenancy/src/Database/Concerns/BelongsToTenant.php on line 19

Steps to reproduce

php artisan tinker

tenancy()->initialize(Tenant::first())

User::first()->tenant

Expected behavior

no messages

Laravel version

8.83.5

stancl/tenancy version

3.5.6

@oscar-ol oscar-ol added the bug Something isn't working label Apr 29, 2022
@stancl stancl added feature New feature or request and removed bug Something isn't working labels May 1, 2022
@stancl
Copy link
Member

stancl commented May 1, 2022

Thanks, we'll change this to use something like a config key.

@stancl stancl removed their assignment May 1, 2022
@stancl stancl closed this as completed in a1c3442 May 15, 2022
stancl added a commit that referenced this issue May 15, 2022
This reverts commit a1c3442.
@ahmedsayedabdelsalam
Copy link

fixed ?

1 similar comment
@hai-shift
Copy link

fixed ?

@oscar-ol
Copy link
Author

@stancl please reopen this issue

@stancl stancl added v4 and removed feature New feature or request labels Jul 25, 2022
@stancl stancl reopened this Jul 25, 2022
@garethnic
Copy link

garethnic commented Aug 17, 2022

Oki so for everyone else wondering, I sorted it out temporarily like this:

In config/tenancy.php I added 'tenant_column' => 'tenant_id',.

I copied the following files from vendor to locations under app/:

  • \Stancl\Tenancy\Database\Concerns\BelongsToTenant::class
  • \Stancl\Tenancy\Database\TenantScope::class

Inside of the boot method in app/Providers/AppServiceProvider.php:

$this->app->bind(BelongsToTenant::class, \Stancl\Tenancy\Database\Concerns\BelongsToTenant::class);
$this->app->bind(TenantScope::class, \Stancl\Tenancy\Database\TenantScope::class);

In those files that I now have locally, I override any instance of BelongsToTenant::$tenantIdColumn with config('tenancy.tenant_column')

Then in my models I just use the local trait use App\Helpers\Traits\BelongsToTenant;.

I also ran php artisan config:clear and composer dumpautoload -o.

I stopped seeing PHP Deprecated messages in tinker. Hope it helps.

@stancl
Copy link
Member

stancl commented Aug 17, 2022

I don't think the app->bind() will have any effect, PHP can't be used like that

@garethnic
Copy link

You're probably right that that bit might be nnecessary. In the past when fighting with Nova overrides on unrelated stuff, adding those bind calls helped. Think I dumped it there out of habit.

@stancl
Copy link
Member

stancl commented Aug 17, 2022

Here it just seems like you're binding your class to the package class (so it's in the opposite direction than what you'd want anyway), and I don't think it gets used because traits use PHP, not Laravel, so the service container bindings won't be able to change anything.

@zach2825
Copy link

@stancl I submitted a PR that resolves this for me locally. I'm not sure that it's the direction you want to go with it but that PR resolves this issue.

stancl added a commit that referenced this issue Oct 1, 2022
@stancl
Copy link
Member

stancl commented Oct 1, 2022

Fixed in 4.x

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

No branches or pull requests

6 participants