PHP code example of imagina / ifillable-module

1. Go to this page and download the library: Download imagina/ifillable-module 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/ */

    

imagina / ifillable-module example snippets


 public $dispatchesEventsWithBindings = [
        'created' => [
            ['path' => 'Modules\Ifillable\Events\CreateField']
        ],
        'creating' => [],
        'updated' => [
            ['path' => 'Modules\Ifillable\Events\CreateField']
        ],
        'updating' => [],
        'deleting' => [
            ['path' => 'Modules\Ifillable\Events\CreateField']
        ],
        'deleted' => []
    ];

public function fields()
    {
        if (isModuleEnabled('Ifillable')) {
            return app(\Modules\Ifillable\Relations\FillablesRelation::class)->resolve($this);
        }
        return new \Imagina\Icore\Relations\EmptyRelation();
    }

public function modelAttributes($request):array
  {
      $attributes = [];

      if ($this->resource->relationLoaded('fields')) {
          $translations = [];
          $currentLocale = app()->getLocale();

          foreach ($this->resource->fields as $field) {
              $isMultilang = false;
              $fieldTitle = $field->title;

              foreach ($field->getAttributes() as $locale => $data) {
                  if (is_array($data) && isset($data['value'])) {
                      $translations[$locale][$fieldTitle] = $data['value'];
                      $isMultilang = true;
                  }
              }

              if ($isMultilang) {
                  $attributes[$fieldTitle] = $translations[$currentLocale][$fieldTitle] ?? null;
              } else {
                  $attributes[$fieldTitle] = $field->value;
              }
          }

          $attributes = array_merge($attributes, $translations);
      }

      return $attributes;
  }
 php
protected array $excludeRelations = ['fields'];