Closed xalunda closed 5 years ago
Hey :wave:,
Thank you for using our package.
We firmly believe that open sourcing our code improves the developer experience. In a pursuit to continue our work, help us by donating to our collective! :heart:
Issues opened by backers of our Open Collective will automatically labelled with the "backer" tag for priority response and resolve times.
Can you confirm that database d3442a527d7b4b08a8053755b87151f1
exists and it fully migrated?
Hi,
Thanks for your fast reply
Yes everything is correct. All I did was change the composer and composer update
On Fri, Mar 15, 2019, 1:12 PM Vytautas Smilingis notifications@github.com wrote:
Can you confirm that database d3442a527d7b4b08a8053755b87151f1 exists and it fully migrated?
β You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/hyn/multi-tenant/issues/752#issuecomment-473280279, or mute the thread https://github.com/notifications/unsubscribe-auth/ACNXvXjDxWW0A3fgNGA1754Fx81lkWWEks5vW5wmgaJpZM4b2bAH .
Try running php artisan tenancy:key:update
command.
Got no output The key did not change The error remains
That's the content of Hyn\Tenancy\Commands\UpdateKeyCommand.php
class UpdateKeyCommand extends Command
{
use DispatchesEvents;
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'tenancy:key:update';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Update tenant users passwords.';
/**
* Execute the console command.
*/
public function handle()
{
$this->emitEvent(new KeyUpdated());
}
}
This doesn't do anything
That command simply iterates over all tenants and updates their database user password. What's weird to me that the error doesn't complain about wrong password, but it says, that it can't find users table inside the tenant database.
Can you post a screenshot of that database in question and tables?
Here is the database screenshot I'm not allowed to post the tables, sorry. Is there something specific to check about it ?
If you are sure that users
table exist on that database, can you post a full trace of the error?
The d3442a527d7b4b08a8053755b87151f1
is a tenant
database.
My users
table has always been in the system
database. There is no users
table in my tenants databases
That makes more sense now. Does your user model have UsesSystemConnection
trait?
HOLY MOLLY!
It did not! It works now! Wondering how it worked until then though.
You absolutely made my day! Thanks a lot π₯
Did you change any other config options, like tenancy.db.default
?
tenancy.db.default => env('TENANCY_DEFAULT_CONNECTION')
.env
file:
TENANCY_DEFAULT_CONNECTION=tenant
I did not change those values
Looks like laravel Passport also needs to be told to use the correct database:
'd3442a527d7b4b08a8053755b87151f1.oauth_personal_access_clients'
Any idea were to do that ?
@xalunda you can extend the passport related models and add the UsesTenantConnection
to the extended models and then read here on how to override default models
or add this to your AppServiceProvider's boot method
$env = app(Environment::class);
if ($fqdn = optional($env->hostname())->fqdn) {
config(['database.default' => 'tenant']);
}
By specifying tenant
as default it forces every model to use tenant connection. Not sure why it worked for you before. I would set the default connection to system
and then add UsesTenantConnection
to your models that need to connect to tenant database.
Otherwise you could try forcing 3rd party model connection through config: https://github.com/hyn/multi-tenant/blob/458fc0220420ecfe6fd11818098c442c48aa910f/assets/configs/tenancy.php#L292-L304 Though I see there's a reported issue on that #751
So, I can set default to system
in the AppServiceProvider?
Every single tenant model is set like in the docs:
use Hyn\Tenancy\Abstracts\TenantModel;
class SomeTable extends TenantModel {}
Would this work?
Just set it in config, not in the provider.
as per @Plytas I also set my default connection to system
in the .env file, and just change the connection to tenant if app(Environment::class)
resolves anything.
@bkintanar as I understand it wouldn't let you use both system and tenant connections at the same time if you are just switching the connection instead of specifying them per model?
@Plytas I have set my .env file to system
by default, but when the app boots, it checks if it is actually accessing a fqdn, and then I forcefully sets the connection to tenant
with the code above.
I've also set the TENANCY_DEFAULT_CONNECTION=system
I don't have @bkintanar 's code to force tenant connection though. Seems like Hyn\Tenancy\Abstracts\TenantModel
does its job.
Good to hear. If your issue is solved, feel free to close it :)
Thanks everyone! That was lighting fast and very effective. π
Yeah, it was one of the solution most people used if they don't want to put the UsesTenantConnection
trait.
One use case not to use the trait is that if you want to reuse your model in system
and tenant
connection
One use case not to use the trait is that if you want to reuse your model in system and tenant connection
Yeah that's smart!
Good afternoon
Following the upgrade guide, I added the
key
intoconfig/tenancy.php
file:Changed the following on my
composer.json
:I'm correctly on php 7.2.1
The main hostname
example.com
works fine. Whenever I try a tenant websitesub.example.com
, I get this error that I can't seem to debug.Looks like some middleware is trying to authenticate the user through it's own database.
Information
tenancy.php config
webserver.php config