Closed SuperDJ closed 1 month ago
Don't think this is a bug in the package. If you use a factory that's your own code, you'd need to point out what specifically is wrong in the package here.
When I call $tenant = Tenant::factory()->create();
in a test I get the following error:
Stancl\Tenancy\Exceptions\TenantCouldNotBeIdentifiedById: Tenant could not be identified with tenant_id
This is comming from:
/vendor/stancl/tenancy/src/Tenancy.php:39 /vendor/stancl/tenancy/src/Tenancy.php:159 /vendor/stancl/tenancy/src/Commands/Migrate.php:51 /vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:36 /vendor/laravel/framework/src/Illuminate/Container/Util.php:43 /vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:95 /vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:35 /vendor/laravel/framework/src/Illuminate/Container/Container.php:690 /vendor/laravel/framework/src/Illuminate/Console/Command.php:213 /vendor/symfony/console/Command/Command.php:279 /vendor/laravel/framework/src/Illuminate/Console/Command.php:182 /vendor/symfony/console/Application.php:1029 /vendor/symfony/console/Application.php:316 /vendor/symfony/console/Application.php:167 /vendor/laravel/framework/src/Illuminate/Console/Application.php:163 /vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php:426 /vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php:358 /vendor/stancl/tenancy/src/Jobs/MigrateDatabase.php:34 /vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:36 /vendor/laravel/framework/src/Illuminate/Container/Util.php:43 /vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:95 /vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:35 /vendor/laravel/framework/src/Illuminate/Container/Container.php:690 /vendor/stancl/jobpipeline/src/JobPipeline.php:68 /vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:36 /vendor/laravel/framework/src/Illuminate/Container/Util.php:43 /vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:95 /vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:35 /vendor/laravel/framework/src/Illuminate/Container/Container.php:690 /vendor/laravel/framework/src/Illuminate/Bus/Dispatcher.php:128 /vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:144 /vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:119 /vendor/laravel/framework/src/Illuminate/Bus/Dispatcher.php:132 /vendor/laravel/framework/src/Illuminate/Bus/Dispatcher.php:98 /vendor/laravel/framework/src/Illuminate/Foundation/helpers.php:444 /vendor/stancl/jobpipeline/src/JobPipeline.php:96 /vendor/laravel/framework/src/Illuminate/Events/Dispatcher.php:458 /vendor/laravel/framework/src/Illuminate/Events/Dispatcher.php:286 /vendor/laravel/framework/src/Illuminate/Events/Dispatcher.php:266 /vendor/laravel/framework/src/Illuminate/Database/Eloquent/Concerns/HasEvents.php:233 /vendor/laravel/framework/src/Illuminate/Database/Eloquent/Concerns/HasEvents.php:208 /vendor/stancl/virtualcolumn/src/VirtualColumn.php:139 /vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php:1344 /vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php:1162 /vendor/laravel/framework/src/Illuminate/Database/Eloquent/Factories/Factory.php:338 /vendor/laravel/framework/src/Illuminate/Collections/Traits/EnumeratesValues.php:257 /vendor/laravel/framework/src/Illuminate/Database/Eloquent/Factories/Factory.php:333 /vendor/laravel/framework/src/Illuminate/Database/Eloquent/Factories/Factory.php:287 /tests/Feature/Api/AuthenticateTest.php:27
For support questions please use our Discord.
This appears to be caused by the events being fired too early. Using $tenant = Tenant::factory()->createQuietly()
instead prevents the events from being fired.
Bug description
On
Tenant::factory()->create()
no tenant migrations are migrated as tenant is alwaysnull
inStancl\Tenancy\Commands\Migrate
.Steps to reproduce
Tenant
model with corresponding factory;Tenant::factory()->create()
method;Stancl\Tenancy\Commands\Migrate
,$tenant
will always be null an thus not performing migrations. The corresponding databases are created. A exception is thrown instead.Expected behavior
When using
Tenant::factory()->create()
tenant migrations should be migrated.Laravel version
11.26
stancl/tenancy version
3.8.5