PHP code example of amarenkov / laravel-mutable-content-filament

1. Go to this page and download the library: Download amarenkov/laravel-mutable-content-filament 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/ */

    

amarenkov / laravel-mutable-content-filament example snippets


use Amarenkov\MutableContentFilament\Filament\Resources\Fields\FieldResource;
use Amarenkov\MutableContentFilament\Filament\Resources\Fields\Resources\Usage\UsageResource;
use Amarenkov\MutableContentFilament\Filament\Resources\Lovs\LovResource;
use Amarenkov\MutableContentFilament\Filament\Resources\Lovs\Resources\Items\ItemResource;

public function panel(Panel $panel): Panel
{
    return $panel
        // ...
        ->resources([
            FieldResource::class,
            UsageResource::class,
            LovResource::class,
            ItemResource::class,
        ]);
}

use Amarenkov\MutableContentFilament\Filament\Resources\Base\Resource;

class ProjectResource extends Resource
{
    protected static ?string $model = Project::class;
    protected static ?string $recordTitleAttribute = 'code';

    public static function getPages(): array
    {
        return [
            'index'  => ListProjects::route('/'),
            'create' => CreateProject::route('/create'),
            'view'   => ViewProject::route('/{record}'),
            'edit'   => EditProject::route('/{record}/edit'),
        ];
    }
}

use Amarenkov\MutableContentFilament\Filament\Resources\Base\Pages\CreateRecord;

class CreateProject extends CreateRecord
{
    protected static string $resource = ProjectResource::class;
}

protected static function formComponentsFromFields(?array $scopes = null)
{
    $components = parent::formComponentsFromFields($scopes);

    $components['field_type']->live();

    $components['lov_code']->hidden(
        fn (Get $get) => $get('field_type') !== FieldType::TYPE_LOV_ITEM
    );

    return $components;
}