SQLSTATE[42S02] Error - Multi Tenancy

I'm trying to figure out multi tenancy, have ran through a couple docs / youtube videos and getting the following error:
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'axis.academy_user' doesn't exist

select `academies`.*, `academy_user`.`user_id` as `pivot_user_id`, `academy_user`.`academy_id` as `pivot_academy_id` from `academies` inner join `academy_user` on `academies`.`id` = `academy_user`.`academy_id` where `academy_user`.`user_id` = 1 and `academies`.`deleted_at` is null
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'axis.academy_user' doesn't exist

select `academies`.*, `academy_user`.`user_id` as `pivot_user_id`, `academy_user`.`academy_id` as `pivot_academy_id` from `academies` inner join `academy_user` on `academies`.`id` = `academy_user`.`academy_id` where `academy_user`.`user_id` = 1 and `academies`.`deleted_at` is null
I have an academies table, but no academy_user - I'm not sure what this is, surely that should just be user? Appreciate any help on this as I'm a bit out my depth.
Solution:
Found the problem, posting here for future search of anyone having the same. May seem a simple one, but I didn't see anywhere in the docs where this was a step hence my struggling:
Jump to solution
5 Replies
Dennis Koch
Dennis Koch8mo ago
Based on the information given it's hard to tell. Maybe share the error via Flare as mentioned in #✅┊rules. When is the error happening? On every page load?
Solution
Hightower
Hightower8mo ago
Found the problem, posting here for future search of anyone having the same. May seem a simple one, but I didn't see anywhere in the docs where this was a step hence my struggling:
Hightower
HightowerOP8mo ago
SOLUTION: Many to many relationship between user and tenant so requires an additional table. Created a migration for academy_user and a couple of columns for these IDs:
public function up(): void
{
Schema::create('academy_user', function (Blueprint $table) {
$table->id();
$table->foreignIdFor(Academy::class)->index();
$table->foreignIdFor(User::class)->index();
$table->timestamps();
});
}
public function up(): void
{
Schema::create('academy_user', function (Blueprint $table) {
$table->id();
$table->foreignIdFor(Academy::class)->index();
$table->foreignIdFor(User::class)->index();
$table->timestamps();
});
}
Dennis Koch
Dennis Koch8mo ago
This is some Laravel stuff. That's why you won't find it in our docs, but in Laravel's
Hightower
HightowerOP8mo ago
That makes sense, but as I say a bit out my depth so sometimes even knowing where to look is something
Want results from more Discord servers?
Add your server