benbjurstrom/glint
最新稳定版本:v0.1.4
Composer 安装命令:
composer require benbjurstrom/glint
包简介
A Cloudflare Images library for Laravel
README 文档
README
️⚠️ WARNING: This package is still in development and not ready for production use. ⚠️
For example, currently there's no option to use a custom model in place of the package's Image and ImageType models. I'll add that functionality once my implementation is stable.
Installation
Install the package via composer:
composer require benbjurstrom/glint
Add cloudflare credentials to your services config file:
// 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'), ],
Then publish and run the migrations with:
php artisan vendor:publish --tag="glint-migrations"
php artisan migrate
Usage
Client upload
Since there's so many ways to handle authentication, authorization, and response formatting this is left to the user to implement. But an example controller might look something like this:
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); }
Credits
License
The MIT License (MIT). Please see License File for more information.
统计信息
- 总下载量: 29
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 4
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-03-09