kharanenka/oc-data-file-model

Trait helps to get attached to the model file data

1.1.0 2017-08-27 15:11 UTC

This package is auto-updated.

Last update: 2024-04-29 03:50:26 UTC


README

Trait helps to get attached to the model file data. For 'attache one' relation returns data array with fields:

  • (string) full_path
  • (string) path
  • (string) title
  • (string) alt

For 'attache many' relation returns array with files data.

#Installation Require this package in your composer.json and update composer.


"kharanenka/oc-data-file-model": "1.*"

#Uses

class MyModel extends Model
{
    use DataFileModel;
    
    public $attachOne = ['preview_image' => 'System\Models\File'];
    public $attachMany = ['images' => 'System\Models\File'];
}

$obModel = MyModel::first();
$arFileData = $obModel->getFileData('preview_image');
$arFileList = $obModel->getFileListData('images');

Result:

$arFileData = [
    'full_path' => '...',
    'path'      => '...',
    'title'     => '...',
    'alt'       => '...',
];

$arFileList = [
    [
        'full_path' => '...',
        'path'      => '...',
        'title'     => '...',
        'alt'       => '...',
    ],[
        'full_path' => '...',
        'path'      => '...',
        'title'     => '...',
        'alt'       => '...',
    ],
];