承接 rainetro/laravel-imagebox 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

rainetro/laravel-imagebox

最新稳定版本:0.1.8

Composer 安装命令:

composer require rainetro/laravel-imagebox

包简介

Use images with Eloquent models in Laravel

README 文档

README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

Use images with Eloquent models in Laravel. This package provides a simple way to attach images to Eloquent models to use in your web applications.

This package is inspired by spatie/laravel-medialibrary.

Installation

You can install the package via composer:

composer require rainetro/laravel-imagebox

You can publish and run the migrations with:

php artisan vendor:publish --provider="Rainet\ImageBox\ImageBoxServiceProvider" --tag="migrations"
php artisan migrate

You can (optionally) publish the config file with:

php artisan vendor:publish --provider="Rainet\ImageBox\ImageBoxServiceProvider" --tag="config"

This is the contents of the published config file:

return [
    'disk' => env('IMAGE_BOX_DISK', 'public'),
    'queue_connection_name' => env('QUEUE_CONNECTION', 'sync'),
    'queue_name' => '',
    'model' => \Rainet\ImageBox\Box\Models\Image::class,
    'folder_generator' => \Rainet\ImageBox\Box\FolderGenerator\DefaultFolderGenerator::class,
];

Usage

Attach images to your models

Ensure that your model implements the ImageBoxInterface. Add the ImageBoxTrait trait to the model. Implement the registerImageCollections() method. This method is used to define the image collections for your model. You can define one or more image collections by chaining the addImageCollection() method. Implement the registerImageCollectionConversions() method. This method is used to define the conversions for your image collections. Inside this method, you can chain the addConversion() method to add conversions to a specific image collection.

use Illuminate\Database\Eloquent\Model;
use Rainet\ImageBox\ImageBoxInterface;
use Rainet\ImageBox\ImageBoxTrait;

class Post extends Model implements ImageBoxInterface
{
    use ImageBoxTrait;

    //  ...

    public function registerImageCollections(): void
    {
        $this
            ->addImageCollection('image')
            ->acceptsMimeTypes(['image/jpeg', 'image/jpg', 'image/png', 'image/gif', 'image/webp']);
    }

    public function registerImageCollectionConversions(): void
    {
        $this
            ->getImageCollection('image')
            ->addConversion('thumb')
            ->width(480)
            ->quality(90);

        // $this
        //     ->getImageCollection('image')
        //     ->addConversion('medium')
        //     ->width(600)
        //     ->height(600)
        //     ->quality(90);
    }
}

Use the image method to attach images to your model.

$post = Post::find(1);
$post
    ->addImage($request->file('image'))
    ->toCollection('image');

You can also use the image() or images() methods to retrieve the image(s).

$post->load('image');
$post->load('images');

Testing (Coming Soon)

We are actively working on implementing comprehensive testing for this package. Stay tuned for updates as we continue to improve the testing coverage.

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Credits

License

The MIT License (MIT). Please see License File for more information.

统计信息

  • 总下载量: 19
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-06-04

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固