PHP code example of yemenpoint / filament-custom-fields

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

    

yemenpoint / filament-custom-fields example snippets


composer 

php artisan vendor:publish --tag="filament-custom-fields-migrations"
php artisan vendor:publish --tag="filament-custom-fields-config"

//then migrate
php artisan migrate




use Yemenpoint\FilamentCustomFields\Resources\CustomFieldResource;
use Yemenpoint\FilamentCustomFields\Resources\CustomFieldResponseResource;

return [
    'resources' => [
        CustomFieldResource::class,
        CustomFieldResponseResource::class,
    ],
    //model options will appear in CustomFieldResource 
    'models' => [
//        \App\Models\Trying::class => "trying",
    ],
    
    "navigation_group" => "Custom Fields",
    "custom_fields_label" => "Custom Fields",
    "custom_field_responses_label" => "Custom Fields Responses",
];


use Yemenpoint\FilamentCustomFields\CustomFields\FilamentCustomFieldsHelper;


    protected function afterCreate()
    {
        FilamentCustomFieldsHelper::handle_custom_fields_request($this->data, $this->getModel(), $this->record->id);
    }

    protected function getFormSchema(): array
    {
        return [
            ...parent::getFormSchema(),
            ...FilamentCustomFieldsHelper::custom_fields_form($this->getModel(), data_get($this->record,"id"))
        ];
    }



use Yemenpoint\FilamentCustomFields\CustomFields\FilamentCustomFieldsHelper;

    public function afterSave()
    {
    //this will handle_custom_fields_request
        FilamentCustomFieldsHelper::handle_custom_fields_request($this->data, $this->getModel(), $this->record->id);
    }

    protected function getFormSchema(): array
    {
        return [
            ...parent::getFormSchema(),
            ...FilamentCustomFieldsHelper::custom_fields_form($this->getModel(), data_get($this->record,"id"))
        ];
    }

    use Yemenpoint\FilamentCustomFields\CustomFields\FilamentCustomFieldsHelper;


   // show CustomFieldResponses in Resource column
    public static function table(Table $table): Table
    {
        return $table
            ->columns([
                FilamentCustomFieldsHelper::custom_fields_column()
            ]);
    }