konnco / laravel-onimage
Boost up your coding speed, no worries about managing image anymore.
v2.x-dev
2020-10-27 05:48 UTC
Requires
- php: >=7.2.0
- illuminate/contracts: ^5.6|^6.0|^7.0|^8.0
- illuminate/database: ^5.6|^6.0|^7.0|^8.0
- illuminate/support: ^5.6|^6.0|^7.0|^8.0
- intervention/image: ^2.5
- intervention/imagecache: ^2.4
- ralouphie/mimey: ^2.1
Requires (Dev)
- orchestra/testbench: 3.8.* || ^4.0
- phpunit/phpunit: ^8.0
This package is auto-updated.
Last update: 2024-10-07 10:02:27 UTC
README
This package is designed to boost up your developing time in managing your image in Laravel framework.
This package based on the famous Intervention/Image
Installation
composer require composer require konnco/laravel-onimage
php artisan vendor:publish
php artisan migrate
Configuration
you can find onimage configuration here. config/onimage.php
Usage
Add onimage traits into your model
namespace App; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\SoftDeletes; class News extends Model { use \Konnco\Onimage\Onimage; }
Quick Example
Uploading Image
$news = News::find(1); $news->onImageSet('featured', 'https://images.unsplash.com/photo-1562887250-9a52d844ad30?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=2089&q=80'); // Or for new instance $news = new News; $news->title = "hello world"; $news->save(); $news->onImageSet('featured', 'https://images.unsplash.com/photo-1562887250-9a52d844ad30?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=2089&q=80'); // You can pass an array too $news->onImageSet('featured', [ 'https://images.unsplash.com/photo-1562887250-9a52d844ad30?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=2089&q=80', 'https://images.unsplash.com/photo-1562887250-9a52d844ad30?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=2089&q=80', 'https://images.unsplash.com/photo-1562887250-9a52d844ad30?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=2089&q=80' ]);
Multiple Image
// Pushing into existing attribute $news = News::find(1); $news->onImagePush('featured', 'https://images.unsplash.com/photo-1562887250-9a52d844ad30?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=2089&q=80'); // You can insert it as an array too $news->onImagePush('featured', [ 'https://images.unsplash.com/photo-1562887250-9a52d844ad30?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=2089&q=80', 'https://images.unsplash.com/photo-1562887250-9a52d844ad30?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=2089&q=80', 'https://images.unsplash.com/photo-1562887250-9a52d844ad30?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=2089&q=80']);
Checking is attribute available
$news = News::find(1); $news->onImageHas('featured');
Getting single image
$news = News::find(1); $news->onImageFirst('featured', 1);
Getting image collections
$news = News::find(1); $news->onImageGet('featured');
Deleting Image
$news = News::find(1); $news->onImageDelete('featured', 1); // Or delete batch $news->onImageDelete('featured', [1, 2, 3]);
Upload Type
You can insert these types into onimage field :
- string - Path of the image in filesystem.
- string - URL of an image (allow_url_fopen must be enabled).
- string - Binary image data.
- string - Data-URL encoded image data.
- string - Base64 encoded image data.
- resource - PHP resource of type gd. (when using GD driver)
- object - Imagick instance (when using Imagick driver)
- object - Intervention\Image\Image instance
- object - SplFileInfo instance (To handle Laravel file uploads via Symfony\Component\HttpFoundation\File\UploadedFile)
Authors
Contributing
we appreciate all contributions, feel free to write some code or request package.