Skip to content

Commit

Permalink
converted getNestedResource to a non-static method
Browse files Browse the repository at this point in the history
  • Loading branch information
brentkelly committed Jun 13, 2024
1 parent 54e4236 commit 1b7049f
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/Actions/NestedCreateAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ trait NestedCreateAction
{
protected function configureCreateAction(CreateAction $action): void
{
$resource = static::getNestedResource();
$resource = $this->getNestedResource();

/** @var Ancestor $ancestor */
$ancestor = $resource::getAncestor();
Expand Down
2 changes: 1 addition & 1 deletion src/Actions/NestedEditAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ protected function configureEditAction(Tables\Actions\EditAction $action): void
parent::configureEditAction($action);

$action->url(
fn (Model $record) => static::getNestedResource($record)::getUrl(
fn (Model $record) => $this->getNestedResource($record)::getUrl(
'edit',
['record' => $record],
)
Expand Down
2 changes: 1 addition & 1 deletion src/Actions/NestedViewAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ protected function configureViewAction(Tables\Actions\ViewAction $action): void
parent::configureViewAction($action);

$action->url(
fn (Model $record) => static::getNestedResource($record)::getUrl(
fn (Model $record) => $this->getNestedResource($record)::getUrl(
'view',
['record' => $record],
)
Expand Down
4 changes: 2 additions & 2 deletions src/Concerns/NestedRelationManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ trait NestedRelationManager
use NestedEditAction;
use NestedViewAction;

public static function getNestedResource(?Model $record = null): string
public function getNestedResource(?Model $record = null): string
{
if (property_exists(static::class, 'nestedResource')) {
return static::$nestedResource;
}

return Filament::getModelResource($record ?? static::getRelationship()->getRelated());
return Filament::getModelResource($record ?? $this->getRelationship()->getRelated());
}
}
14 changes: 7 additions & 7 deletions src/Pages/CreateRelatedRecord.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public function getRecord(): Model

protected function authorizeAccess(): void
{
abort_unless(static::getNestedResource()::canCreate(), 403);
abort_unless($this->getNestedResource()::canCreate(), 403);
}

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

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

protected function associateRecordWithTenant(Model $record, Model $tenant): Model
{
$relationship = static::getNestedResource($record)::getTenantRelationship($tenant);
$relationship = $this->getNestedResource($record)::getTenantRelationship($tenant);

if ($relationship instanceof HasManyThrough) {
$record->save();
Expand Down Expand Up @@ -284,7 +284,7 @@ public function form(Form $form): Form
*/
protected function getForms(): array
{
$resource = static::getNestedResource();
$resource = $this->getNestedResource();

return [
'form' => $this->form($resource::form(
Expand All @@ -303,13 +303,13 @@ public function getFormStatePath(): ?string
return 'data';
}

public static function getNestedResource(?Model $record = null): string
public function getNestedResource(?Model $record = null): string
{
if (property_exists(static::class, 'nestedResource')) {
return static::$nestedResource;
}

return Filament::getModelResource($record ?? static::getRelation()->getRelated());
return Filament::getModelResource($record ?? $this->getRelation()->getRelated());
}

public static function canCreateAnother(): bool
Expand All @@ -324,7 +324,7 @@ public static function disableCreateAnother(): void

protected function getRedirectUrl(): string
{
$resource = static::getNestedResource($this->getRecord());
$resource = $this->getNestedResource($this->getRecord());

if ($resource::hasPage('view') && $resource::canView($this->getRecord())) {
return $resource::getUrl('view', ['record' => $this->getRecord(), ...$this->getRedirectUrlParameters()]);
Expand Down

0 comments on commit 1b7049f

Please sign in to comment.