tjslash/cto-set-image-trait

1.0.2 2022-12-22 04:18 UTC

This package is auto-updated.

Last update: 2024-10-22 08:09:43 UTC


README

Latest Version on Packagist Total Downloads The Whole Fruit Manifesto

This package for set attribute images field for Laravel Eloquent models.

Installation

Via Composer

composer require tjslash/cto-set-image-trait

Usage

namespace App\Models;
use Tjslash\CtoSetImageTrait\Traits\SetImageTrait;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Model;
...

class SimpleModel extends Model 
{
    use SetImageTrait;
    
    /**
     * Image options
     * 
     * @return array
     */
    protected $imageOptions = [
        'image' => [
            'destination_path' => 'category',
            'disk' => 'public'
        ]
    ];
    
    /**
     * Get/set image attribute
     * 
     * @return Attribute
     */
    public function image() : Attribute
    {
        return Attribute::make(
            get: fn($value) => $value,
            set: fn($value) => self::setImage($value, 'image')
        );
    }
    
    ...
}

Change log

Changes are documented here on Github. Please see the Releases tab.

Testing

composer test

Contributing

Please see contributing.md for a todolist and howtos.

Security

If you discover any security related issues, please email vakylenkox@gmail.com instead of using the issue tracker.

Credits

License

This project was released under MIT, so you can install it on top of any Backpack & Laravel project. Please see the license file for more information.