everywell/imagination

A Laravel package that allows to handle images on your models seamlessly
1,261 2
Install
composer require everywell/imagination
Latest Version:v2.0.6
PHP:^5.5.9 || ^7.0
License:MIT
Last Updated:Jan 25, 2021
Links: GitHub  ·  Packagist
Maintainer: EveryWell

Imagination

A Laravel package that allows to handle images on your Eloquent models seamlessly.

Installation

To install this package just a few steps are needed

Composer

Pull this package in through Composer using the following command inside your terminal:

composer require everywell/imagination

Service Provider

Add the package to your application service providers in config/app.php file.

'providers' => [
    
    /*
     * Laravel Framework Service Providers...
     */
    Illuminate\Foundation\Providers\ArtisanServiceProvider::class,
    Illuminate\Auth\AuthServiceProvider::class,
    ...
    
    /**
     * Third Party Service Providers...
     */
    EveryWell\Imagination\ImaginationServiceProvider::class,

],

Config File

Publish the package config file to your aplication running the following command inside your terminal:

php artisan vendor:publish --provider="EveryWell\Imagination\ImaginationServiceProvider"

Trait and Contract

Include HasImages trait and also implement HasImages contract inside your model class.

use EveryWell\Imagination\Traits\HasImages;
use EveryWell\Imagination\Contracts\HasImages as HasImagesContract;

class News extends Model implements HasImagesContract
{
    use HasImages;

Images attribute

Add an images array attribute to your model containing the fields that should be handled as images.

use EveryWell\Imagination\Traits\HasImages;
use EveryWell\Imagination\Contracts\HasImages as HasImagesContract;

class News extends Model implements HasImagesContract
{
    use HasImages;
    
    protected $fillable = [
        'title',
        'text',
        'banner',
        'image'
    ];
        
    protected $images = [
        'banner',
        'image' => [
            'discard_original' => true, // Optional: if true, doesn't save the original version of the image
            'dimensions' => [           // Optional: specifies different dimensions than the default config
                [
                    'name' => 'thumb',
                    'width' => 150
                ],
                [
                    'name' => 'small',
                    'width' => 250
                ],
                [
                    'name' => 'regular',
                    'width' => 600
                ]
            ]
        ]
    ];

And that's it!

Related Packages

antennaio/laravel-clyde

Image uploads and manipulation for Laravel, a wrapper around Glide

2,621 29
spatie/laravel-responsecache

Speed up a Laravel application by caching the entire response

9,315,725 2,810
maartenstaa/laravel-41-route-caching

This package allows you to cache your routes definitions, thereby speeding up ea...

384,139 25
anakadote/laravel-5-image-manager

Image resizing and cropping package for Laravel 5.

8,935 14
spatie/laravel-medialibrary

Associate files with Eloquent models

45,713,789 6,158