zing / laravel-eloquent-images
Manage images for Laravel eloquent
3.3.0
2024-03-18 14:37 UTC
Requires
- php: ^8.0
- illuminate/database: ^8.0 || ^9.0 || ^10.0 || ^11.0
- illuminate/support: ^8.0 || ^9.0 || ^10.0 || ^11.0
Requires (Dev)
- mockery/mockery: ~1.3.3 || ^1.4.2
- orchestra/testbench: ^6.0 || ^7.0 || ^8.0 || ^9.0
- phpunit/phpunit: ^9.3.3 || ^10.0
README
Requires PHP 8.0+
Require Laravel Eloquent Images using Composer:
composer require zing/laravel-eloquent-images
Usage
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.