gabrielesbaiz/unsplash-toolkit
Composer 安装命令:
composer require gabrielesbaiz/unsplash-toolkit
包简介
A lightweight helper package to handle Unsplash photos
README 文档
README
A lightweight helper package to handle Unsplash photos
Original code from marksitko/laravel-unsplash
Features
- ✅ Fluent api to use the Unsplash within Laravel applications
- ✅ Works seamlessly with Laravel facades
Installation
You can install the package via composer:
composer require gabrielesbaiz/unsplash-toolkit
You can publish and run the migrations with:
php artisan vendor:publish --tag="unsplash-toolkit-migrations"
php artisan migrate
You can publish the config file with:
php artisan vendor:publish --tag="unsplash-toolkit-config"
This is the contents of the published config file:
return [ 'access_key' => env('UNSPLASH_ACCESS_KEY'), 'store_in_database' => env('UNSPLASH_STORE_IN_DATABASE', false), 'disk' => env('UNSPLASH_STORAGE_DISK', 'local'), 'app_name' => env('UNSPLASH_APP_NAME', 'your_app_name'), ];
Usage
Basic Usage
Take a look at the full Unsplash API documentation https://unsplash.com/documentation
Random Photos
// Returns the http response body. $twoRandomPhotosOfSomePeoples = UnsplashToolkit::randomPhoto() ->orientation('portrait') ->term('people') ->count(2) ->toJson(); // Store the image in on your provided disc $theNameFromTheStoredPhoto = UnsplashToolkit::randomPhoto() ->orientation('landscape') ->term('music') ->randomPhoto() ->store(); ];
Photos
$photos = UnsplashToolkit::photos()->toJson(); $photo = UnsplashToolkit::photo($id)->toJson(); $photosStatistics = UnsplashToolkit::photosStatistics($id)->toJson(); $trackPhotoDownload = UnsplashToolkit::trackPhotoDownload($id)->toJson();
Users
$user = UnsplashToolkit::user($username)->toJson(); $userPortfolio = UnsplashToolkit::userPortfolio($username)->toJson(); $userPhotos = UnsplashToolkit::userPhotos($username)->toJson(); $userLikes = UnsplashToolkit::userLikes($username)->toJson(); $userCollections = UnsplashToolkit::userCollections($username)->toJson(); $userStatistics = UnsplashToolkit::userStatistics($username)->toJson();
Search
$search = UnsplashToolkit::search() ->term('buildings') ->color('black_and_white') ->orientation('squarish') ->toJson(); $searchCollections = UnsplashToolkit::searchCollections() ->query('events') ->page($pageNumber) ->toJson(); $searchUsers = UnsplashToolkit::searchUsers() ->query('search_term') ->toJson();
Collections
$collectionsList = UnsplashToolkit::collectionsList() ->page($pageNumber) ->perPage($itemsPerPage) ->toJson(); $featuredCollection = UnsplashToolkit::featuredCollection() ->page($pageNumber) ->perPage($itemsPerPage) ->toJson(); $showCollection = UnsplashToolkit::showCollection() ->id($collectionId) ->toJson(); $showCollectionPhotos = UnsplashToolkit::showCollectionPhotos() ->id($collectionId) ->toJson(); $showCollectionRelatedCollections = UnsplashToolkit::showCollectionRelatedCollections() ->id($collectionId) ->toJson();
Stats
$totalStats = UnsplashToolkit::totalStats()->toJson(); $monthlyStats = UnsplashToolkit::monthlyStats()->toJson();
Usage with Database
If you wanna persist automaticly some informations (i.e. Copyrights) about you stored images you have to run the published migrations.
Set the .env variable
UNSPLASH_STORE_IN_DATABASE=true
When you execute store(), the image is stored in your provided disc and informations like
- the unsplash photo id
- the stored image name
- author name
- author link
Note that these informations are all required to use a Unsplash photo on your website.
Trait
You can also use the HasUnsplashables Trait on any model.
Example with HasUnsplashables Trait on the User Model
use Illuminate\Foundation\Auth\User as Authenticatable; use Gabrielesbaiz\UnsplashToolkit\Traits\HasUnsplashables; class User extends Authenticatable { use HasUnsplashables; // ... }
Now you are able to use it like:
// store the unsplash asset in a morphToMany relation $unsplashAsset = UnsplashToolkit::randomPhoto()->store(); User::unsplash()->save($unsplashAsset); // retrive all related unsplash assets User::find($userId)->unsplash();
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.
gabrielesbaiz/unsplash-toolkit 适用场景与选型建议
gabrielesbaiz/unsplash-toolkit 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 9.76k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 03 月 02 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「Gabriele Sbaiz」 「unsplash-toolkit」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 gabrielesbaiz/unsplash-toolkit 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 gabrielesbaiz/unsplash-toolkit 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 gabrielesbaiz/unsplash-toolkit 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A lightweight helper package to handle Eloquent model duplication.
Custom Laravel Nova 4 map detail field
A lightweight heklper package to handle WhatsApp messages using api.whatsapp.com
Custom Laravel Nova 4 map card.
Customer Nova field for JSON data.
A colour-coded indicator field for Laravel Nova
统计信息
- 总下载量: 9.76k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 28
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-03-02