Open almooradi-dev opened 1 year ago
I solve it (but got a different error 😅, I am trying to figure it out)
But for the main issue above, I solve it by editing the ChildResourceLink::getUrl()
public function getUrl(): ?string
{
$baseParams = [];
if (property_exists($this->table->getLivewire(), 'urlParameters')) {
$baseParams = $this->table->getLivewire()->urlParameters;
}
$param = Str::camel(Str::singular($this->resourceClass::getParent()::getSlug())); // 👈 Here
// Which is the same used in "NestedResource::getParentTree()" in the "urlPlaceholder" parameter
return $this->resourceClass::getUrl(
'index',
[...$baseParams, $param => $this->record->getKey()] // 👈 Here
);
}
The second issue, is related to that one (because of the models in a subdirectory)
In the NestedResource::getEloquentQuery()
, when calling the static::getParentAccessor()
in the whereHas
we got academic\Course
which is wrong of course, and it should only be course
So my nested resource I just add this:
public static function getParentAccessor(): string
{
return 'course';
}
Don't do this
Because it will affect other places
So I override the getEloquentQuery()
in my nested resource
public static function getEloquentQuery(string|int|null $parent = null): Builder
{
$query = static::getModel()::query(); // 👈 Change here
$parentModel = static::getParent()::getModel();
$key = (new $parentModel)->getKeyName();
$query->whereHas(
'course', // 👈 Change here
fn (Builder $builder) => $builder->where($key, '=', $parent ?? static::getParentId())
);
return $query;
}
The second issue, is related to that one (because of the models in a subdirectory) In the
NestedResource::getEloquentQuery()
, when calling thestatic::getParentAccessor()
in thewhereHas
we gotacademic\Course
which is wrong of course, and it should only becourse
So my nested resource I just add this:
public static function getParentAccessor(): string { return 'course'; }
EDIT
Don't do this Because it will affect other places So I override the
getEloquentQuery()
in my nested resourcepublic static function getEloquentQuery(string|int|null $parent = null): Builder { $query = static::getModel()::query(); // 👈 Change here $parentModel = static::getParent()::getModel(); $key = (new $parentModel)->getKeyName(); $query->whereHas( 'course', // 👈 Change here fn (Builder $builder) => $builder->where($key, '=', $parent ?? static::getParentId()) ); return $query; }
I create pull request thanks
https://github.com/Sevendays-Digital/filament-nested-resources/pull/6
Hello,
I have 2 resources:
And the models of these resources are in a subdirectory
App/Models/Academic/....
So when trying to get the child URL usingChildResourceLink::make(...)
I gotMissing parameter: academic/course
So I trace your code's functions:
Go to
NestedResource::getUrl()
And check what the final$params
is giving me, and I found thisThe first one
academic\Course
is from the first$params
variable, and the second oneacademic/course
is from the$list
variableGo to
ChildResourceLink::getUrl()
(where the function in step1
is called)As you can see, this logic will be working perfectly for Models that are directly under the
App\Models
directory (and not in a subdirectory)So, is there a solution to this from my side, or we should edit the function in step
2
?