https://github.com/konnco/laravel-onimage
The best package for maintain your images
https://github.com/konnco/laravel-onimage
image image-manager intervention-image laravel
Last synced: about 2 months ago
JSON representation
The best package for maintain your images
- Host: GitHub
- URL: https://github.com/konnco/laravel-onimage
- Owner: konnco
- License: mit
- Created: 2019-12-18T03:10:31.000Z (almost 6 years ago)
- Default Branch: v2
- Last Pushed: 2021-05-07T02:35:20.000Z (over 4 years ago)
- Last Synced: 2024-01-24T03:01:17.341Z (almost 2 years ago)
- Topics: image, image-manager, intervention-image, laravel
- Language: PHP
- Homepage:
- Size: 158 KB
- Stars: 4
- Watchers: 2
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# Laravel Onimage
[](https://travis-ci.org/Konnco/laravel-onimage)
[](https://packagist.org/packages/konnco/laravel-onimage)
[](https://packagist.org/packages/konnco/laravel-onimage)
[](https://packagist.org/packages/konnco/laravel-onimage)
[](https://packagist.org/packages/konnco/laravel-onimage)
[](https://github.styleci.io/repos/228747586)
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](http://image.intervention.io)
## Installation
```php
composer require composer require konnco/laravel-onimage
```
```php
php artisan vendor:publish
```
```php
php artisan migrate
```
## Configuration
you can find onimage configuration here. `config/onimage.php`
## Usage
Add onimage traits into your model
```php
namespace App;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class News extends Model {
use \Konnco\Onimage\Onimage;
}
```
## Quick Example
### Uploading Image
```php
$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
```php
// 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
```php
$news = News::find(1);
$news->onImageHas('featured');
```
### Getting single image
```php
$news = News::find(1);
$news->onImageFirst('featured', 1);
```
### Getting image collections
```php
$news = News::find(1);
$news->onImageGet('featured');
```
### Deleting Image
```php
$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
[//]: contributor-faces
## Contributing
we appreciate all contributions, feel free to write some code or request package.