imagina/imedia-module

Imagina imedia laravel module

Installs: 6

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 1

Forks: 20

Type:laravel-module


README

Private Files Configurations

- The bucker must have the permissions configured correctly
- Read and write should be set only for the allowed user

Implementation with Modules

In the Entity (Models/Entity)

  • Add Events
 public array $dispatchesEventsWithBindings = [
    'created' => [['path' => 'Modules\Imedia\Events\CreateMedia']],
    'creating' => [],
    'updated' => [['path' => 'Modules\Imedia\Events\UpdateMedia']],
    'updating' => [],
    'deleting' => [['path' => 'Modules\Imedia\Events\DeleteMedia']],
    'deleted' => []
];
  • Add the zones
/**
* Media Fillable
*/
public $mediaFillable = [
    'mainimage' => 'single'
];
  • Add relation:
/**
* Relation Media
* Make the Many To Many Morph
*/
public function files()
{
    if (isModuleEnabled('Imedia')) {
        return app(\Modules\Imedia\Relations\FilesRelation::class)->resolve($this);
    }
    return new \Imagina\Icore\Relations\EmptyRelation();
}

In Transformer (Transformers/EntityTransformer)

  • Add relation with files
//Implementation with Media
 return [
    'files' => $this->whenLoaded('files', fn() => $this->files->byZones($this->mediaFillable, $this)),
];

Endpoint | Attributes Example

  • To Media single , add zone and file id.
attributes[medias_single][$zone] = $fileId

Example: Zone = mainimage

attributes[medias_single][mainimage] = 1
  • To Media gallery, add zone and files array ids.
attributes[medias_multi][$zone][files][] = $fileId

Example: Zone = gallery

attributes[medias_multi][gallery][files][] = 1
attributes[medias_multi][gallery][files][] = 2