Skip to content

Commit

Permalink
fix: check correct resource on CreateRelatedRecord
Browse files Browse the repository at this point in the history
fix: check correct resource on CreateRelatedRecord
  • Loading branch information
lukas-frey authored Apr 28, 2024
2 parents 8b38fb1 + ee0a7a0 commit 0a27a08
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/Pages/CreateRelatedRecord.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,7 @@ public function getRecord(): Model

protected function authorizeAccess(): void
{
// TODO: maybe need to switch resource to other resource
abort_unless(static::getResource()::canCreate(), 403);
abort_unless(Filament::getModelResource($this->getRelation()->getRelated())::canCreate(), 403);
}

protected function fillForm(): void
Expand Down Expand Up @@ -181,7 +180,7 @@ protected function handleRecordCreation(array $data): Model
}

if (
static::getResource()::isScopedToTenant() &&
Filament::getModelResource($record)::isScopedToTenant() &&
($tenant = Filament::getTenant())
) {
return $this->associateRecordWithTenant($record, $tenant);
Expand All @@ -207,7 +206,7 @@ protected function associateRecordWithParent(Model $record, Model $owner)

protected function associateRecordWithTenant(Model $record, Model $tenant): Model
{
$relationship = static::getResource()::getTenantRelationship($tenant);
$relationship = Filament::getModelResource($record)::getTenantRelationship($tenant);

if ($relationship instanceof HasManyThrough) {
$record->save();
Expand Down

0 comments on commit 0a27a08

Please sign in to comment.