nodes-php / assets by nodes

Package to make upload and generation of urls matching the files
11,237
3
3
Package Data
Maintainer Username: nodes
Maintainer Contact: cr@nodes.dk (Casper Rasmussen)
Package Create Date: 2015-11-08
Package Last Update: 2020-04-23
Home Page: http://nodesagency.com
Language: PHP
License: MIT
Last Refreshed: 2024-04-19 15:03:20
Package Statistics
Total Downloads: 11,237
Monthly Downloads: 0
Daily Downloads: 0
Total Stars: 3
Total Watchers: 3
Total Forks: 4
Total Open Issues: 3

Assets

A easy integration for handling files with Laravel.

Total downloads Monthly downloads Latest release Open issues License Star repository on GitHub Watch repository on GitHub Fork repository on GitHub Travis tests StyleCI Code Climate

📝 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

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

Follow Nodes PHP on Twitter Tweet Nodes PHP

📄 License

This package is open-sourced software licensed under the MIT license