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
composer require composer require konnco/laravel-onimage
php artisan vendor:publish
php artisan migrate
you can find onimage configuration here. config/onimage.php
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;
}
$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'
]);
// 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']);
$news = News::find(1);
$news->onImageHas('featured');
$news = News::find(1);
$news->onImageFirst('featured', 1);
$news = News::find(1);
$news->onImageGet('featured');
$news = News::find(1);
$news->onImageDelete('featured', 1);
// Or delete batch
$news->onImageDelete('featured', [1, 2, 3]);
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)
we appreciate all contributions, feel free to write some code or request package.