Tenant with an extra layer of ownership - uploading documents
Hi.
I have set up Filament with multitenancy, and I am using a classic "Team" model. I have one more layer below a team, that I call buckets:
A team can have many buckets, and a bucket can belong to one team.
Then, under a bucket, the user can upload many documents, meaning that: a bucket can have many documents, and a document can belong to one bucket.
Now, I have set up a new resource called
DocumentResource
, but I am simply unable to figure out how I can upload a simple document via a header action, since the document should belong to a bucket, and not to a team directly.
In my App
panel, I have specified this:
Then, on the DocumentResource
I have set a relationship:
Then, under the ListDocuments
page, I would like to have the "Upload Document" modal:
When I upload, it fails, since Filament is looking for a team_id
on the documents
table. But there is none, only a bucket_id
5 Replies
Just put this in your documentresource that shouldn’t scope for tenants:
protected static bool $isScopedToTenant = false;
Although you have to be careful to limit access to the buckets yourself.
But how can I then upload a document and relate it to a bucket?
After some more thinking -- basically all the users will see is scoped like this:
Team -> Bucket -> Data
Is there a better way to achieve this, so the data always relates to the active bucket?
Why not give the bucket a team_id then?
The bucket does indeed have a
team_id
, perhaps I am just confused about how to scope this correctly..I got the same problem. The way around it is that, I add team_id in model Document's $fillable. In ListDocument
Actions\CreateAction::make()
->form([
FileUpload::make('name')
->required()
->storeFileNamesIn('original_filename')
])
->mutateFormDataUsing(function (array $data): array {
$data['team_id'] = Filament::getTenant()->id;
return $data;
});
and you should remove $tenantRelationshipName from youor DocumentResource.