monurakkaya/laravel-image

This package is abandoned and no longer maintained. No replacement package was suggested.
There is no license information available for the latest version (1.1.0) of this package.

A simple package to manage model related images

1.1.0 2018-08-18 21:16 UTC

This package is auto-updated.

Last update: 2022-02-14 23:55:51 UTC


README

composer require monurakkaya/laravel-image

Configuration

php artisan vendor:publish --tag=laravel-image
php artisan migrate

It will create the imageables table.

Usage

Change

use Illuminate\Database\Eloquent\Model; line to

use Monurakkaya\LaravelImage\Support\Image as Model;

Then in your model :

$model->uploadImages($request->file('input_name'))

If you want to remove images after model has been deleted, simply add

Model::observe(Monurakkaya\LaravelImage\Observers\ImageObserver)

in your

app/Providers/AppServiceProvider.php boot method

    public function boot()
    {
        Model::observe(Monurakkaya\LaravelImage\Observers\ImageObserver);
    }

Configuration

There is two type of images thumbnail, poster.

Default, poster dimensions 1920x1080 and thumbnail 450x300.

If you want to change these dimensions simply add public properties to your related model

    class Gallery extends Model {
    
        protected $poster = [
            'width' => 800,
            'height' => 800 
        ];
        
        protected $thumbnail = false; // Package won't generate a thumbnail for uploaded images.
    }

Querying

Images Collection

    $gallery = Gallery::with('images')->first();
    $gallery->images; //returns image collection.

Make Default Image

    $image = $gallery->images()->first();
    $gallery->makeDefault($image);

Get Default Image

    $gallery = Gallery::with('defaultImage')->first();
    $gallery->defaultImage; //returns image model

Delete an Image

    $gallery->removeImage($image)

Component

This package comes with built in image management panel. It can be useable with @laravel-image component

    @laravelImage([
        'model' => $gallery
    ])
    @endlaravelImage

(Requires bootstrap3)

Here is a screenshot

component

Translation

Refer to /resources/lang/en/laravel-image.php