F
Filamentβ€’2y ago
Avriant

First Time Filament Project, stuck on M:M relationship πŸ†˜

Background: It's my first Filament and Backend-heavy project. *Any help would be immensely appreciated! * I plan to use Filament dashboard for user input, multiple users can belong to the same org, but will see the same dashboard. All content will only be shown to a single user authenticated as "admin." There can be different orgs.
I want: 1. To have user_id, company_id, role_id saved in my table when I input data on Filament (right now I only have Filament user who inputs data and it's saved in the DB, but M:M table is not filled 😦 ). 2. To find the right plugin on Filament to use for 1-org-many-users-that-can-edit-the-same-inputs scenario (was thinking about this one: https://filamentphp.com/plugins/companies, but I have a feeling this one only works for org=user scenario). 3. To understand how to setup "roles" migration/logic for a Filament project (see 1.3 below). 4. What to do with user migration if I need other fields to register a user (not only name, email and psw, but maybe org_id and phone number)?
I have: 1. Migrations 1.1. Users
$table->id();
$table->string('name');
$table->string('email')->unique();
$table->string('phone', 12)->unique()->nullable();
$table->timestamp('email_verified_at')->nullable();
[...]
$table->id();
$table->string('name');
$table->string('email')->unique();
$table->string('phone', 12)->unique()->nullable();
$table->timestamp('email_verified_at')->nullable();
[...]
1.2 Companies

$table->id();
$table->string('name', 100)->unique();
$table->string('address', 100)->unique();
$table->smallInteger('total')->nullable();
$table->timestamps();

$table->id();
$table->string('name', 100)->unique();
$table->string('address', 100)->unique();
$table->smallInteger('total')->nullable();
$table->timestamps();
1.3 Roles
$table->id();
$table->string('name', 20);
$table->json('privileges');
$table->id();
$table->string('name', 20);
$table->json('privileges');
1.4 User_Role (M:M)
$table->id();
$table->foreignId('role_id')->references('id')->on(table: 'roles');
$table->foreignId('user_id')->references('id')->on(table: 'users');
$table->foreignId('company_id')->references('id')->on(table: 'companies');
$table->timestamps();
$table->id();
$table->foreignId('role_id')->references('id')->on(table: 'roles');
$table->foreignId('user_id')->references('id')->on(table: 'users');
$table->foreignId('company_id')->references('id')->on(table: 'companies');
$table->timestamps();
2. Filament v.2.17.49 3. Doctrine/dbal I'll be rerunning migrations in the background and try to figure it out in the meantime.
4 Replies
Dan Harrin
Dan Harrinβ€’2y ago
im not really sure how to help lets take this one step at a time and look at a specific problem whats going wrong with filament when you try and use the many to many relationship? what features did you use? what code did you use?
Avriant
AvriantOPβ€’2y ago
Thank you so much for reacting! I setup a second project with clean DB and tried https://filamentphp.com/plugins/companies, for now it works like a charm, but I'm still in the middle of checking things! Will update this post once I figure more things out! Okay, I was asked to make it more simple and specific, so here's the deal How to modify (and is it really the best practice) default migrations generated by /plugins/companies? Background: I tried to add a simple field in Company migration (which actually worked), however be it dbal or default Filament resource generation, once I run the command and refresh the page I get
Route [filament.pages.companies/create] not defined
Route [filament.pages.companies/create] not defined
Resetting the route cache (solution found upon Googling) did not help. I simply tried to output the field I added in default Companies plugin migration to the dashboard. I suppose maybe I should just create separate migrations and reference the company_id generated by the Companies plugin?
Dan Harrin
Dan Harrinβ€’2y ago
plugin support should be asked in the specific channel, like #companies
Avriant
AvriantOPβ€’2y ago
Apologies, will do!
Want results from more Discord servers?
Add your server