PHPackages                             devfelipereis/uploadtrait - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [File &amp; Storage](/categories/file-storage)
4. /
5. devfelipereis/uploadtrait

ActiveLibrary[File &amp; Storage](/categories/file-storage)

devfelipereis/uploadtrait
=========================

A simple upload trait for Laravel

21.9k1PHP

Since Mar 6Pushed 7y ago1 watchersCompare

[ Source](https://github.com/devfelipereis/uploadtrait)[ Packagist](https://packagist.org/packages/devfelipereis/uploadtrait)[ RSS](/packages/devfelipereis-uploadtrait/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependenciesVersions (2)Used By (0)

Simple upload trait for Laravel
===============================

[](#simple-upload-trait-for-laravel)

A simple upload trait for laravel. It will upload to the local storage if in development and to a s3 bucket if in production/staging.

For production, you need to follow the laravel documentation to set s3 as your default cloud disk.

Just tested with Laravel 5.4+. But it should work with Laravel 5.x.

Note: This is something made for my setup and works good. I like storage for dev and s3 for production. Feel free to change whatever you like to meet your needs ;)

```
When not using s3, the generated url will be something like this: site.com/storage?path=something/something.jpg
Do not use this in production, it's only for dev.
It is vulnerable with Full Path Disclosure (https://www.owasp.org/index.php/Full_Path_Disclosure)

```

### How to install

[](#how-to-install)

```
composer require devfelipereis/uploadtrait:dev-master

```

If you are running Laravel 5.4 or below, you will need to add the service provider to the providers array in your app.php config as follows:

```
DevFelipeReis\UploadTrait\UploadTraitServiceProvider::class

```

Now see the example below to understand how to use it.

Example
=======

[](#example)

In your model, set the base path for your uploads:

```
...
use DevFelipeReis\UploadTrait\UploadTrait;

class Company extends Model
{
    use UploadTrait;

    ...

    public function getBaseUploadFolderPath() {
        return 'companies/' . $this->id . '/';
    }
}
```

Now in your controller...

```
public function store(CreateCompanyRequest $request)
{
    ...
    $inputs = $request->except('logo');
    $company = $this->companyRepository->create($inputs);

    // Company logo
    $company_logo = $request->file('logo');
    if ($company_logo) {
        $company->logo = $company->uploadFile($company_logo);
        // $company->logo will be something like: companies/1/8e5dc57cb5d80532f52e13597c5f0b68.jpg
    }

    $company->save();

    ...
}
```

### How to access the image?

[](#how-to-access-the-image)

Finally, inside the view:

```
...

...
```

### How to delete the image?

[](#how-to-delete-the-image)

Maybe you want to delete that image, try this:

```
$company->deleteUploadFor('photo');
```

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity19

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/2862216?v=4)[Felipe Reis](/maintainers/felipereis)[@felipereis](https://github.com/felipereis)

---

Top Contributors

[![devfelipereis](https://avatars.githubusercontent.com/u/5348752?v=4)](https://github.com/devfelipereis "devfelipereis (22 commits)")

---

Tags

laravels3traitupload

### Embed Badge

![Health badge](/badges/devfelipereis-uploadtrait/health.svg)

```
[![Health](https://phpackages.com/badges/devfelipereis-uploadtrait/health.svg)](https://phpackages.com/packages/devfelipereis-uploadtrait)
```

###  Alternatives

[knplabs/gaufrette

PHP library that provides a filesystem abstraction layer

2.5k39.8M123](/packages/knplabs-gaufrette)[google/cloud-storage

Cloud Storage Client for PHP

34390.8M125](/packages/google-cloud-storage)[illuminate/filesystem

The Illuminate Filesystem package.

15261.6M2.6k](/packages/illuminate-filesystem)[superbalist/flysystem-google-storage

Flysystem adapter for Google Cloud Storage

26320.6M30](/packages/superbalist-flysystem-google-storage)[creocoder/yii2-flysystem

The flysystem extension for the Yii framework

2931.7M62](/packages/creocoder-yii2-flysystem)[flowjs/flow-php-server

PHP library for handling chunk uploads. Works with flow.js html5 file uploads.

2451.6M15](/packages/flowjs-flow-php-server)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
