rpwebdevelopment/has-image-laravel

A package for simplifying image handling on Laravel eloquent models

Maintainers

Package info

github.com/rpwebdevelopment/has-image-laravel

pkg:composer/rpwebdevelopment/has-image-laravel

Fund package maintenance!

rpwebdevelopment

Statistics

Installs: 3

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

1.0.1 2026-06-18 07:58 UTC

This package is auto-updated.

Last update: 2026-06-18 08:04:28 UTC


README

Packagist Version Packagist Downloads License: MIT

The has-image-laravel package is designed to be a lightweight package to simplify image handling on Laravel models, currently rather than having to handle uploaded files in your controllers, usually leading to significant code duplication.

This package allows for image upload handling (including SVG sanitization) on models to be quickly and easily configured.

Installation

You can install the package via composer:

composer require rpwebdevelopment/has-image-laravel

You can publish the config file with:

php artisan vendor:publish --tag="has-image-laravel-config"

The config file dictates the default storage disk to be used, while this can be overridden at a model level you may find it useful to configure to your default disk:

return [
    'default' => 'local',
];

Usage

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use RPWebDevelopment\HasImageLaravel\Dto\ImageDetails;
use RPWebDevelopment\HasImageLaravel\Traits\HasImage;

class Foo extends Model
{
    use HasImage;
    
    protected $fillable = [
        ...
        'logo',
        ...
    ];

    public function getImageDetails(): ImageDetails
    {
        /**
        * $storageDisk parameter is optional, if excluded the 
        * default disk from your configuration will be accepted.
        *
        * $maintainFilename parameter is optional (false by default)
        * if true, the uploaded file will maintain the original filename
        * as uploaded. If false a hashed filename will be used.
        */
        return ImageDetails::create(
            imageDirectory: 'DIR_NAME',
            imageFields: ['logo'],
            storageDisk: 'public',
            maintainFilename: true
        );
    }
}

Changelog

Please see CHANGELOG for more information on what has changed recently.

Credits

License

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