unisharp/laravel-uploadable

A simple package to attach files to a eloquent model.

Maintainers

👁 g0110280

Package info

github.com/UniSharp/laravel-uploadable

pkg:composer/unisharp/laravel-uploadable

Statistics

Installs: 3 048

Dependents: 0

Suggesters: 0

Stars: 5

Open Issues: 0

dev-master 2018-11-19 06:00 UTC

Suggests

None

Provides

None

Conflicts

None

Replaces

None

MIT 0a5a6a675c7c976d61c4fa2080a66daafb9f9d69

  • UniSharp Ltd. <unisharp-service.woop@unisharp.com>

fileuploadlaravel

This package is auto-updated.

Last update: 2026-06-15 18:59:39 UTC


README

👁 Latest Version on Packagist
👁 Software License
👁 Build Status
👁 Coverage Status
👁 Quality Score
👁 Total Downloads

A simple package to attach files to a eloquent model.

Installation

composer require unisharp/laravel-uploadable dev-master

Configuration

Set configuration in config/uploadable.php

return [
 // Set image orientate enable or disable
 'use_image_orientate' => false,

 // Set thumbnail size
 'thumbs' => [
 's' => '96x96',
 'm' => '256x256',
 'l' => '480x480'
 ],

 // Set image handler
 'plugins' => [
 ImageHandler::class
 ]
];

Usages

Use trait in the model

namespace App;

use Illuminate\Database\Eloquent\Model;
use Unisharp\Uploadable\CanUpload;

class Product extends Model
{
 use CanUpload;
 
 public function image()
 {
 return $this->morphOne(Image::class, 'imageable');
 }
}

Manually upload and Delete files

// Upload a file
$product = new Product();
$product->upload(request()->file());

// Delete a file
$file = $product->files()->first();
$product->removeFiles($file->id);

// Delete files
$files = $product->files->pluck('id');
$product->removeFiles($files);

Upload/Delete through APIs

// POST /files/ & DELETE /files/{file}
UniSharp\Uploadable\UploaderManager::route();

// POST /files/
UniSharp\Uploadable\UploaderManager::route(['store']);

// POST /files/ with callback
UniSharp\Uploadable\UploaderManager::route(['store'], function () {
 ...
});

Customize image handler

Image Handler

use Intervention\Image\Facades\Image;
use Illuminate\Filesystem\FilesystemAdapter;

class CustomImageHandler {
 public function handle(FilesystemAdapter $storage, $path)
 {
 $image = Image::make($storage->path($path));
 
 ...
 
 $image->save();
 }
}

Set Custom image handler in config/uploadable.php

return [
 'plugins' => [
 CustomImageHandler::class
 ]
];