nodes / assets
Package to make upload and generation of urls matching the files
Requires
- illuminate/container: >=5.2.0 <6.15.0
- illuminate/support: >=5.2.0 <6.15.0
- league/flysystem-aws-s3-v3: ~1.0
- nodes/cache: ^1.0
- nodes/core: ^1.1
- symfony/http-foundation: 2.8.*||3.0.*||3.1.*||3.2.*||3.3.*||4.3.*||4.4.*
Requires (Dev)
- orchestra/testbench: ~3.4
- phpunit/phpunit: ~5.7
- dev-master
- 1.1.21
- 1.1.20
- 1.1.19
- 1.1.18
- 1.1.17
- 1.1.16
- 1.1.15
- 1.1.14
- 1.1.13
- 1.1.12
- 1.1.11
- 1.1.10
- 1.1.9
- 1.1.8
- 1.1.7
- 1.1.6
- 1.1.5
- 1.1.4
- 1.1.3
- 1.1.2
- 1.1.1
- 1.1.0
- 1.0.9
- 1.0.8
- 1.0.7
- 1.0.6
- 1.0.5
- 1.0.4
- 1.0.3
- 1.0.2
- 1.0.1
- 1.0.0
- 0.1.3
- 0.1.2
- 0.1.1
- 0.1.0
- dev-feature/laravel6-only
- dev-develop
- dev-feature/laravel6
- dev-hotfix/fix-nodes-s3-provider
This package is auto-updated.
Last update: 2024-05-17 19:36:05 UTC
README
A easy integration for handling files with Laravel.
📝 Introduction
One thing we at Nodes have been missing in Laravel is a fast easy file storage integration system.
The Storage
facade made it easier, but we still need the option to upload from differente formats and store to a very specific folder structure, retrieve a path and be able to create urls to serve api and sites.
📦 Installation
To install this package you will need:
- Laravel 5.1+
- PHP 5.5.9+
You must then modify your composer.json
file and run composer update
to include the latest version of the package in your project.
"require": { "nodes/assets": "^1.1" }
Or you can run the composer require command from your terminal.
composer require nodes/assets:^1.1
🔧 Setup
Setup service provider in config/app.php
Nodes\Assets\ServiceProvider::class
Setup alias in config/app.php
'Assets' => Nodes\Assets\Support\Facades\Assets::class
Publish config files
php artisan vendor:publish --provider="Nodes\Assets\ServiceProvider"
If you want to overwrite any existing config files use the --force
parameter
php artisan vendor:publish --provider="Nodes\Assets\ServiceProvider" --force
S3 + ImgIX
In general.php config
'upload' => [ 'provider' => function () { $s3Config = config('filesystems.disks.s3'); $awsS3Config = config('nodes.assets.provider.aws-s3'); return new \Nodes\Assets\Upload\Providers\AmazonS3($awsS3Config, $s3Config); }, ], 'url' => [ 'provider' => function () { $imgIxConfig = config('nodes.assets.providers.imgix'); return new \Nodes\Assets\Url\Providers\ImgIX($imgIxConfig); }, ],
Make sure to have .env setup
AMAZON_BUCKET=bucket
AMAZON_KEY=key
AMAZON_SECRET=secret
AMAZON_REGION=eu-west-1
CDN_BASE_URL=nodes-cdn-development.imgix.net
Vapor Cloud
In general.php config
<?php return [ 'upload' => [ 'provider' => function () { $s3Config = config('filesystems.disks.s3'); $vaporCloudConfig = config('nodes.assets.providers.vapor-cloud'); return new \Nodes\Assets\Upload\Providers\VaporCloud($s3Config, $vaporCloudConfig); }, ], 'url' => [ 'provider' => function () { $vaporCloudConfig = config('nodes.assets.providers.vapor-cloud'); return new \Nodes\Assets\Url\Providers\VaporCloud($vaporCloudConfig); }, ], ];
Make sure to have .env setup
AMAZON_BUCKET=bucket AMAZON_KEY=key AMAZON_SECRET=secret AMAZON_REGION=eu-west-1 AMAZON_CLOUDFRONT_URL={insert imgix base url here locally} AMAZON_CLOUDFRONT_URL_DATA={insert imgix base url here locally}
Public Folder
Public folder method can resize images. To setup, you need Intervention image lib. To install run
composer require intervention/image
Then add the following to app.php
providers array
Intervention\Image\ImageServiceProvider::class
aliases array
'Image' => Intervention\Image\Facades\Image::class
finally run
php artisan vendor:publish --provider="Intervention\Image\ImageServiceProviderLaravel5"
Configure for public folder
Modify the configuration in config/nodes/assets/general.php
return [ 'upload' => [ 'provider' => function () { return new \Nodes\Assets\Upload\Providers\PublicFolder(); }, ], 'url' => [ 'provider' => function () { return new \Nodes\Assets\Url\Providers\PublicFolder(); }, ], ];
⚙ Usage
Global methods
function assets_add($file, $folder = null, UploadSettings $settings = null)
function assets_add_uploaded_file(UploadedFile $file, $folder = null, UploadSettings $settings = null)
function assets_add_url($url, $folder = null, UploadSettings $settings = null)
function assets_add_data_uri($dataUri, $folder = null, UploadSettings $settings = null)
function assets_get($path, UrlSettings $settings = null)
Facade methods
Assets::add($file, $folder = null, UploadSettings $settings = null)
Assets::addFromUploadedFile(UploadedFile $file, $folder = null, UploadSettings $settings = null)
Assets::addFromUrl($url, $folder = null, UploadSettings $settings = null)
Assets::addFromDataUri($dataUri, $folder = null, UploadSettings $settings = null)
Assets::get($path)
🏆 Credits
This package is developed and maintained by the PHP team at Nodes
📄 License
This package is open-sourced software licensed under the MIT license