Nested resources #6127
Closed
haringsrob
started this conversation in
Ideas
Replies: 3 comments 1 reply
-
I was able to make this work a bit better by extending custom list/edit/create resource pages, here's an example for reference: <?php
namespace App\Filament\Nesting;
use Filament\Resources\Pages\CreateRecord;
use Illuminate\Support\Facades\Route;
abstract class NestedCreatePage extends CreateRecord
{
use NestedPageTrait;
public mixed $parentRecord;
public function mount(): void
{
$this->parentRecord = Route::current()->parameter('parentRecord');
parent::mount();
}
} <?php
namespace App\Filament\Nesting;
use Filament\Resources\Resource;
use Illuminate\Database\Eloquent\Model;
trait NestedPageTrait
{
protected function getBreadcrumbs(): array
{
/** @var Resource $resource */
$resource = static::getResource();
$breadcrumb = $this->getBreadcrumb();
/** @var Resource $parentResource */
$parentResource = static::getResource()::getParent();
/** @var Model $parentModel */
$parentModel = $parentResource::getModel();
$parentModelTitle = $parentResource::getGlobalSearchResultTitle($parentModel::find($this->parentRecord));
return array_merge(
[$parentResource::getUrl() => $parentResource::getBreadcrumb()],
[$parentResource::getUrl('edit', ['record' => $this->parentRecord]) => $parentModelTitle],
[$resource::getUrl('index', ['parentRecord' => $this->parentRecord]) => $resource::getBreadcrumb()],
(filled($breadcrumb) ? [$breadcrumb] : []),
);
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
-
Can make it two levels? |
Beta Was this translation helpful? Give feedback.
0 replies
-
I think nested resources are built in now. or there are at least some great packages for this. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hey,
So I started working out a parent/child nested routing.
While I can do a part of it, I feel it would be better to add parts to filament core to make this work.
Before I dive into it, I would like to check if this is something that you want to be at core, conceptually there are also some different approaches that can be taken.
Here is a dummy implementation of what I am adding:
The issue for now I am running into is the getURl method.
This should also render a nested breadcrumb, this cannot be done from resource classes and needs changes in the page classes. I would like to avoid the need to change every list/view/create page class.
In addition, conceptually, I wanted to show this in the navigation only when you are in the context.
So the file tree would show:
ParentRecordName
Beta Was this translation helpful? Give feedback.
All reactions