PHPackages                             rootinc/laravel-s3-file-model - 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. rootinc/laravel-s3-file-model

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

rootinc/laravel-s3-file-model
=============================

S3 File Model

1.1.1(3y ago)06.4k1MITPHPPHP &gt;=8.0.2

Since Aug 31Pushed 3y ago2 watchersCompare

[ Source](https://github.com/rootinc/laravel-s3-file-model)[ Packagist](https://packagist.org/packages/rootinc/laravel-s3-file-model)[ RSS](/packages/rootinc-laravel-s3-file-model/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (4)Versions (14)Used By (0)

Laravel S3 File Model
=====================

[](#laravel-s3-file-model)

Provides a File Model that supports direct uploads / downloads from S3 for a Laravel App.

Installation
------------

[](#installation)

1. `composer require rootinc/laravel-s3-file-model`
2. Run `php artisan vendor:publish --provider="RootInc\LaravelS3FileModel\FileModelServiceProvider"` to create `File` model in `app`, `FileTest` in `tests\Unit`, `FileFactory` in `database\factories`, `2020_03_12_152841_create_files_table` in `database\migrations`, and `FileController` in `app\Http\Controllers`
3. Run `php artisan vendor:publish  --provider="Aws\Laravel\AwsServiceProvider` which adds `aws.php` in the `config` folder
4. In the `aws.php` file, change `'region' => env('AWS_REGION', 'us-east-1'),` to use `AWS_DEFAULT_REGION`
5. In `config\filesystems.php`, add key `'directory' => '', // root dir` to `public` and add key `'directory' => env('AWS_UPLOAD_FOLDER'),` to `s3`
6. In `tests\TestCase`, add this function:

```
protected function get1x1RedPixelImage()
{
    return "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8DwHwAFBQIAX8jx0gAAAABJRU5ErkJggg==";
}

```

7. Update routing. We can use this as an example: `Route::apiResource('files', 'FileController')->only(['index', 'store', 'update', 'destroy']);`
8. 🎉

Update from 0.1.\* to 0.2.\*
----------------------------

[](#update-from-01-to-02)

If we are using API versioning paradigm, 0.2.\* lets us abstract the file model so that in a child class, we can import a different version of the File.

For example, our `FileController` would look something like this:

```
