It's possible that the issue is related to the database connection. When using multi-tenancy, each tenant should have its own database connection. Make sure that you have set up the database connections correctly in your config/database.php file.
Also, make sure that you are running the migrations for each tenant separately. You can do this by running the following command:
php artisan tenancy:migrate --tenants=foo,bar
This will run the migrations for the foo and bar tenants.
If you have already done this and are still experiencing issues, try running the create method instead of the factory method to create the users. For example:
App\Models\Tenant::all()->runForEach(function () {
App\Models\User::create([
'name' => 'John Doe',
'email' => '[email protected]',
'password' => bcrypt('password'),
]);
});
This will create a user with the specified name, email, and password for each tenant.
If none of these solutions work, try debugging the issue by adding some dd statements to your code to see where it's failing. For example:
App\Models\Tenant::all()->runForEach(function () {
dd('Creating user for tenant');
App\Models\User::factory()->create();
});
This will output the string "Creating user for tenant" for each tenant, allowing you to see where the code is failing.