vdauchy/eloquent-flysystem-adaptor

0.3.2 2021-05-27 12:42 UTC

This package is auto-updated.

Last update: 2024-05-29 04:42:23 UTC


README

Build Status Total Downloads Latest Stable Version License

Introduction

This package is an Adaptor for Flysystem using Laravel's ORM (Eloquent).

In config\filesystems.php add your new disk as:

return [
    'disks' => [
        /* Name your disk as you wish */
        'my_sql_disk' => [
            /* Use 'eloquent' driver that is registered by this package. */
            'driver' => 'eloquent',
            /* Optional: Set your custom model that extends the base Model to use different tables per disk */
            'model' => CustomContentModel::class,
            /* Optional: Set a custom callable to generate urls or just overwrite the static method 'getUrl()' */
            'getUrl' => [CustomContentModel::class, 'getSomeCustomUrl']
        ]   
    ]
];

Create as many models as you wish like:

use VDauchy\EloquentFlysystemAdaptor\models\Content;

class CustomContentModel extends Content 
{
    /**
     * Example of `getUrl` overwrite to generate URLs using the UUID.
     */
    static public function getUrl(string $path, ?array $metadata): string
    {
        return route('my.custom.content', ['uuid' => $metadata['uuid']]);
    }
}

Create controllers like:

Route::get('my-custom-content/{uuid}', function (string $uuid) {
    $content = CustomContentModel::fromUuid($uuid);
    /* TODO: Add checks for public/private visibility and improve type/mime handling */
    return response($content->contents, 200, ['Content-Type' => $content->mimetype]);
})
->where('uuid', '^[a-z0-9\-]{36}$')
->name('my.custom.content');

Maintenance

Here are the steps to develop/test this package using docker:

# Make sure no image with the same tag exists.
docker image rm php-cli-eloquent-flysystem-adaptor:latest -f;

# Build new image with the expected extensions.
docker build . -t php-cli-eloquent-flysystem-adaptor:latest;

# Update vendors.
docker run \
    --volume $(pwd):/usr/src/app \
    php-cli-eloquent-flysystem-adaptor:latest \
    composer update;
    
# Run unit tests.
docker run \
    --volume $(pwd):/usr/src/app \
    php-cli-eloquent-flysystem-adaptor:latest \
    composer unit;
    
# Run static analysis.
docker run \
    --volume $(pwd):/usr/src/app \
    php-cli-eloquent-flysystem-adaptor:latest \
    composer lint;
    
# Run style check.
docker run \
    --volume $(pwd):/usr/src/app \
    php-cli-eloquent-flysystem-adaptor:latest \
    composer fmt;

License

The MIT License (MIT). Please see License File for more information.