PHP code example of guava / filament-nested-resources
1. Go to this page and download the library: Download guava/filament-nested-resources library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
guava / filament-nested-resources example snippets
use Filament\Resources\Resource;
use Guava\FilamentNestedResources\Concerns\NestedResource;
class ArtistResource extends Resource
{
use NestedResource;
// If using Relation Manager:
public static function getRelations(): array
{
return [
AlbumsRelationManager::class,
];
}
public static function getPages(): array
{
return [
'index' => Pages\ListArtists::route('/'),
'create' => Pages\CreateArtist::route('/create'),
'edit' => Pages\EditArtist::route('/{record}/edit'),
'view' => Pages\ViewArtist::route('/{record}'),
// In case of relation page.
// Make sure the name corresponds to the name of your actual relationship on the model.
'albums' => Pages\ManageArtistAlbums::route('/{record}/albums'),
// Needed to create child records
// The name should be '{relationshipName}.create':
'albums.create' => Pages\CreateArtistAlbum::route('/{record}/albums/create'),
];
}
public static function getAncestor(): ?Ancestor
{
return null;
}
}
use Filament\Resources\Resource;
use Guava\FilamentNestedResources\Concerns\NestedResource;
class AlbumResource extends Resource
{
use NestedResource;
public static function getRelations(): array
{
return [
// Repeat the same for Song Resource
];
}
public static function getAncestor() : ?Ancestor
{
// Configure the ancestor (parent) relationship here
return Ancestor::make(
'albums', // Relationship name
'artist', // Inverse relationship name
);
}
}
use Filament\Resources\Pages\CreateRecord;
use Guava\FilamentNestedResources\Concerns\NestedPage;
class CreateArtist extends CreateRecord
{
use NestedPage;
//
}
use Filament\Resources\Pages\EditRecord;
use Guava\FilamentNestedResources\Concerns\NestedPage;
class EditArtist extends EditRecord
{
use NestedPage;
//
}
use Filament\Resources\Pages\ListRecords;
use Guava\FilamentNestedResources\Concerns\NestedPage;
class ListArtists extends ListRecords
{
use NestedPage;
//
}
use Guava\FilamentNestedResources\Pages\CreateRelatedRecord;
use Guava\FilamentNestedResources\Concerns\NestedPage;
class CreateArtistAlbum extends CreateRelatedRecord
{
use NestedPage;
// This page also needs to know the ancestor relationship used (just like relation managers):
protected static string $relationship = 'albums';
// We can usually guess the nested resource, but if your app has multiple resources for this
// model, you will need to explicitly define it
// public static string $nestedResource = AlbumResource::class;
}
use Filament\Resources\RelationManagers\RelationManager;
use Guava\FilamentNestedResources\Concerns\NestedRelationManager;
class AlbumsRelationManager extends RelationManager
{
use NestedRelationManager;
// We can usually guess the nested resource, but if your app has multiple resources for this
// model, you will need to explicitly define the it
// public static string $nestedResource = AlbumResource::class;
}
use Filament\Resources\Pages\ManageRelatedRecords;
use Guava\FilamentNestedResources\Concerns\NestedPage;
use Guava\FilamentNestedResources\Concerns\NestedRelationManager;
class ManageArtistAlbums extends ManageRelatedRecords
{
use NestedPage; // Since this is a standalone page, we also need this trait
use NestedRelationManager;
//
}
public static function getBreadcrumbRecordLabel(Model $record)
{
return $record->first_name . ' ' . $record->last_name;
}
public static function getBreadcrumbs(Model $record, string $operation): array
{
return [
'my-custom-url' => 'My custom label',
];
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.