faustbrian/laravel-picible

Picture attachment and management for your Eloquent models.

1.1.0 2018-11-10 06:41 UTC

README

Build Status PHP from Packagist Latest Version License

Installation

Require this package, with Composer, in the root directory of your project.

$ composer require faustbrian/laravel-picible

The package configuration will now be located at app/config/picible.php and the migration at database/migrations/2015_01_30_000000_create_picible_table.php.

To finish the installation you need to migrate the picible table by executing:

php artisan migrate

Usage

Including the Trait

<?php

namespace App;

use BrianFaust\Picible\Contracts\Picible as PicibleContract;
use BrianFaust\Picible\Traits\PicibleTrait;

class User extends Model implements PicibleContract {

    use PicibleTrait;

}

Example

<?php

namespace App\Http\Controllers;

use App\User;
use BrianFaust\Picible\PicibleService as Picible;
use Illuminate\Http\Request;

class PicibleController extends Controller {

    public function index(Request $request, Picible $picible)
    {
        // Load the model the picture will be attached to
        $user = User::find(1);

        // The picture that should be uploaded
        $file = $request->files->all()['picture'];

        // Upload the picture and create a database record
        $picture = $picible->withFile($file)
                         ->withModel($user)
                         ->withAttributes(['slot' => 'trailer'])
                         ->withFilters(['watermark'])
                         ->commit(true);

        // Get the shareable url of the created picture
        $picture = $picible->withFilters(['watermark'])
                         ->getShareableLink($picture);

        // Display the shareable url
        echo($picture);
    }

}

Testing

$ phpunit

Security

If you discover a security vulnerability within this package, please send an e-mail to hello@brianfaust.me. All security vulnerabilities will be promptly addressed.

Credits

License

MIT © Brian Faust