PHP code example of ibrostudio / filament-dynamic-resource-children
1. Go to this page and download the library: Download ibrostudio/filament-dynamic-resource-children 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/ */
ibrostudio / filament-dynamic-resource-children example snippets
use IBroStudio\FilamentDynamicResourceChildren\Concerns\HasDynamicChildren;
class ExampleParentResource extends Resource
{
use HasDynamicChildren;
}
public static function getRelations(): array
{
return [];
}
public static function getPages(): array
{
return [
'index' => Pages\ListExampleParents::route('/'),
'create' => Pages\CreateExampleParent::route('/create'),
'view' => Pages\ViewExampleParent::route('/{record}'),
'edit' => Pages\EditExampleParent::route('/{record}/edit'),
];
}
public static function getRelations(): array
{
return array_merge(
[],
self::getDynamicRelationManagers()
);
}
public static function getPages(): array
{
return array_merge(
[
'index' => Pages\ListExampleParents::route('/'),
'create' => Pages\CreateExampleParent::route('/create'),
'view' => Pages\ViewExampleParent::route('/{record}'),
'edit' => Pages\EditExampleParent::route('/{record}/edit'),
],
self::getDynamicPages()
);
}
use App\Filament\Resources\ExampleParentResource;
use Filament\PluginServiceProvider;
use Spatie\LaravelPackageTools\Package;
use VendorName\MyPlugin\Filament\Resources\ExampleParentResource\Pages\MyFirstPage;
use VendorName\MyPlugin\Filament\Resources\ExampleParentResource\Pages\MySecondPage;
use VendorName\MyPlugin\Filament\Resources\ExampleParentResource\RelationManagers\MyFirstRelationManager;
use VendorName\MyPlugin\Filament\Resources\ExampleParentResource\RelationManagers\MySecondRelationManager;
class MyPluginServiceProvider extends PluginServiceProvider
{
protected array $pages = [
MyFirstPage::class,
MySecondPage::class,
];
protected array $relationManagers = [
MyFirstRelationManager::class,
MySecondRelationManager::class,
];
public function configurePackage(Package $package): void
{
$this->packageConfiguring($package);
$package
->name('my-plugin')
->hasViews();
}
public function packageRegistered(): void
{
parent::packageRegistered();
$this->app->resolving('filament', function () {
ExampleParentResource::addDynamicPages([
'first-page-key' => [
'class' => MyFirstPage::class,
'route' => '/first-page-slug'
],
'second-page-key' => [
'class' => MySecondPage::class,
'route' => '/second-page-slug'
],
]);
ExampleParentResource::addDynamicRelationManagers([
MyFirstRelationManager::class,
MySecondRelationManager::class,
]);
});
}
}