benbjurstrom / glint
为Laravel提供的Cloudflare Images库
v0.1.4
2023-03-29 20:36 UTC
Requires
- php: ^8.1
- ext-gd: *
- benbjurstrom/cloudflare-images-php: ^0.5.0
- illuminate/contracts: ^9.0|^10.0
- kornrunner/blurhash: ^1.2
- sammyjo20/saloon-laravel: ^2.0
- spatie/laravel-package-tools: ^1.14.0
Requires (Dev)
- laravel/pint: ^1.0
- nunomaduro/collision: ^7.9
- nunomaduro/larastan: ^2.0.1
- orchestra/testbench: ^8.0
- pestphp/pest: ^2.0
- pestphp/pest-plugin-arch: ^2.0
- pestphp/pest-plugin-laravel: ^2.0
- phpstan/extension-installer: ^1.1
- phpstan/phpstan-deprecation-rules: ^1.0
- phpstan/phpstan-phpunit: ^1.0
README
️⚠️ 警告:此软件包仍在开发中,尚未准备好用于生产使用。 ⚠️
例如,目前没有选项使用自定义模型替换软件包的Image和ImageType模型。一旦我的实现稳定,我将添加此功能。
安装
使用composer安装此软件包
composer require benbjurstrom/glint
将cloudflare凭证添加到您的服务配置文件中
// config/services.php 'cloudflare' => [ 'account_hash' => env('CLOUDFLARE_IMAGES_ACCOUNT_HASH'), 'account_id' => env('CLOUDFLARE_IMAGES_ACCOUNT_ID'), 'api_token' => env('CLOUDFLARE_IMAGES_API_TOKEN'), 'signing_key' => env('CLOUDFLARE_IMAGES_SIGNING_KEY'), ],
然后使用以下命令发布并运行迁移
php artisan vendor:publish --tag="glint-migrations"
php artisan migrate
用法
客户端上传
由于处理认证、授权和响应格式的有多种方式,因此这部分留给了用户来实现。但一个示例控制器可能如下所示
public function store(Request $request) { Gate::authorize('uploadImages', [ $request->user() ]); $data = $request->validate([ 'type_id' => 'required|uuid|exists:image_types,id', 'model_id' => 'required|uuid', 'model_type' => 'required', ]); $modelName = Relation::getMorphedModel($data['model_type']) ?? $data['model_type']; $model = (new $modelName)->findOrFail($data['model_id']); throw_unless($model instanceof HasImagesInterface, \Exception::class, 'Model does not implement HasImagesInterface' ); $type = ImageType::findOrFail($data['type_id']); $image = $model->addImageFromDraft($type); return response()->json($image); }
鸣谢
许可证
MIT许可证(MIT)。有关更多信息,请参阅许可证文件。