Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/zingimmick/laravel-eloquent-images
Manage images for Laravel eloquent
https://github.com/zingimmick/laravel-eloquent-images
eloquent images laravel
Last synced: 17 days ago
JSON representation
Manage images for Laravel eloquent
- Host: GitHub
- URL: https://github.com/zingimmick/laravel-eloquent-images
- Owner: zingimmick
- License: mit
- Created: 2020-10-17T03:29:06.000Z (about 4 years ago)
- Default Branch: 3.x
- Last Pushed: 2024-05-13T14:48:12.000Z (6 months ago)
- Last Synced: 2024-10-11T21:55:52.154Z (about 1 month ago)
- Topics: eloquent, images, laravel
- Language: PHP
- Homepage:
- Size: 89.8 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Laravel Eloquent Images
> **Requires [PHP 8.0+](https://php.net/releases/)**
Require Laravel Eloquent Images using [Composer](https://getcomposer.org):
```bash
composer require zing/laravel-eloquent-images
```
## Usage```php
use Zing\LaravelEloquentImages\Tests\Models\Product;
use Zing\LaravelEloquentImages\Image;$product = Product::query()->first();
// Add image(s) to model
$product->attachImage("https://avatars.githubusercontent.com/u/26657141");
$product->attachImages([
"https://avatars.githubusercontent.com/u/26657141",
Image::query()->first()
]);
// Remove image(s) from model
$product->detachImage("https://avatars.githubusercontent.com/u/26657141");
$product->detachImages([
"https://avatars.githubusercontent.com/u/26657141",
Image::query()->first()
]);
// Reset images of model
$product->syncImages([
"https://avatars.githubusercontent.com/u/26657141",
Image::query()->first()
]);
// Get images of model
$product->images;
// Eager load images
$products = Product::query()->with('images')->withCount('images')->get();
$products->each(function (Product $product){
$product->images->dump();
$product->images_count;
});
```## License
Laravel Eloquent Images is an open-sourced software licensed under the [MIT license](LICENSE).