PHP code example of saade / filament-extra

1. Go to this page and download the library: Download saade/filament-extra 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/ */

    

saade / filament-extra example snippets


use Saade\FilamentExtra\Forms\Components\RelationManager;
use App\Filament\Resources\YourResource\RelationManagers\YourRelationManager;

RelationManager::make(YourRelationManager::class)
    ->lazy(bool $lazy = true)

use Saade\FilamentExtra\Forms\Components\ColorSelect;

ColorSelect::make('color')

use Filament\Resources\Resource;

use Saade\FilamentExtra\Concerns\HasSoftDeletedRecords;

class YourResource extends Resource
{
    use HasSoftDeletedRecords;
}

use Filament\Resources\Pages\CreateRecord;

use Saade\FilamentExtra\Concerns\NavigationGroupAwareBreadcrumbs;

class CreateYourRecord extends CreateRecord
{
    use NavigationGroupAwareBreadcrumbs;
}

use Filament\Resources\Resource;

class ChildResource extends Resource
{
    public static ?string $parentResource = ParentResource::class;
}

use Filament\Resources\Resource;

class ParentResource extends Resource
{
    public static function getPages(): array
    {
        return [
            'index' => Pages\ManageParents::route('/'),
            'edit' => Pages\EditParent::route('/{record}/edit'),

            // Please note that 'child' can be anything you want. It defaults to the resource slug.
            // If you want to change it, you need to override the $pageNamePrefix property on the child resource pages.
            'child.index' => ChildResource\Pages\ListChildren::route('/{parent}/children'),
            'child.create' => ChildResource\Pages\CreateChild::route('{parent}/children/create'),
            'child.edit' => ChildResource\Pages\EditChild::route('{parent}/children/{record}/edit'),
        ];
    }
}

use Filament\Resources\Pages\ListRecords;

use Saade\FilamentExtra\Concerns\HasParentResource;

class ListChildren extends ListRecords
{
    use HasParentResource;

    // (optional) Define custom relationship key (if it does not match the table name pattern).
    protected ?string $relationshipKey = 'parent_id';

    // (optional) Define custom child page name prefix for child pages (if it does not match the parent resource slug).
    protected ?string $pageNamePrefix = 'child';
}

use Saade\FilamentExtra\Support\Color;

Color::make(name: 'fuchia', shade: 200)
  ->shade(int $shade = 500)   // Set a shade
  ->get()                     // Returns the color as array of shades
  ->toHex()                   // Returns the color as hex value
  ->toRgb()                   // Returns the color as rgb value
  ->collect()                 // Returns the color as a Laravel Collection

use function Saade\FilamentExtra\Support\color;

color(name: 'fuchia', shade: 200)
  ->shade(int $shade = 500)   // Set a shade
  ->get()                     // Returns the color as array of shades
  ->toHex()                   // Returns the color as hex value
  ->toRgb()                   // Returns the color as rgb value
  ->collect()                 // Returns the color as a Laravel Collection

use Filament\Forms;

use function Saade\FilamentExtra\Support\html;

Filament\Forms\Components\SomeField::make()
  ->label(
    html('<span class="text-red-500">*</span> Label')
  )

use Filament\Forms;

use function Saade\FilamentExtra\Support\md;

Filament\Forms\Components\SomeField::make()
  ->label(
    md('### Label')
  )

use Filament\Forms;

use function Saade\FilamentExtra\Support\blade;

Filament\Forms\Components\SomeField::make()
  ->label(
    blade('<x-heroicon::some-icon class="w-5 h-5" /> Label', ['some' => 'data'])
  )