scottybo / laravel-unsplash
Laravel 专用于 Unsplash Api 的包
1.0.0
2020-09-14 14:03 UTC
Requires
- php: >=7.3
- guzzlehttp/guzzle: ~6.0
- illuminate/support: ~7
This package is not auto-updated.
Last update: 2024-09-24 09:33:40 UTC
README
此包包含公共动作
分支并更新以兼容 Laravel 6
安装
通过 Composer
$ composer require scottybo/laravel-unsplash
如果你没有运行 Laravel 5.5(或更高版本),那么请将服务提供者在 config/app.php 中添加
Scottybo\LaravelUnsplash\LaravelUnsplashServiceProvider::class
如果你正在运行 Laravel 5.5+ 的包,则自动发现机制会负责添加服务提供者的魔法。
你必须发布配置以提供自定义服务提供者模板。
$ php artisan vendor:publish --provider="Scottybo\LaravelUnsplash\LaravelUnsplashServiceProvider"
用法
有关参数和其他文档的更多信息,请参阅 unsplash 文档
方法列表
照片
$unsplash = new Scottybo\LaravelUnsplash\Photo(); $photos = $unsplash->photos($params)->get(); // list of all photos $photo = $unsplash->single($id, $params)->get(); // single photo $statistic = $unsplash->statistic($id, $params)->get(); // single photo statistics $link = $unsplash->download($id); // single photo download link $photos = $unsplash->curated($params)->get(); // list of curated photos $photo = $unsplash->random($params)->get(); // random photo
注意:你可以使用 getArray()
代替 get()
来获取结果数组。
注意:single($id, $params)
和 random($params)
有 getID()
和 getURL()
方法来获取 ID 和 URL 以用于 <img>
标签。
$photos = $unsplash->random($params)->getURL(); // return https://source.unsplash.com/WLUHO9A_xik/1600x900
用户
$unsplash = new Scottybo\LaravelUnsplash\User(); $user = $unsplash->single($username, $params)->get(); // single user $portfolio = $unsplash->portfolio($username); // single user's portfolio $photos = $unsplash->photos($username, $params)->get(); // single user's photos $photos = $unsplash->likes($username, $params)->get(); // single user's likes $collections = $unsplash->collections($username, $params)->get(); // single user's collections $statistics = $unsplash->statistics($username, $params)->get(); // single user's statistics
注意:你可以使用 getArray()
代替 get()
来获取结果数组。
收藏
$unsplash = new Scottybo\LaravelUnsplash\Collection(); $collection = $unsplash->collections($params)->get(); // list of all collections $collection = $unsplash->single($id)->get(); // single collections $photos = $unsplash->photos($id, $params)->get(); // collection photos $statistic = $unsplash->statistic($id, $params)->get(); // single collections statistics $collection = $unsplash->curated($params)->get(); // list of curated collections $collection = $unsplash->related($id)->get(); // list of related collections $collection = $unsplash->featured($params)->get(); // list of featured collections
注意:你可以使用 getArray()
代替 get()
来获取结果数组。
搜索
$unsplash = new Scottybo\LaravelUnsplash\Search(); $photos = $unsplash->photo($query, $params)->get(); $collection = $unsplash->collection($query, $params)->get(); $user = $unsplash->user($query, $params)->get();
注意:你可以使用 getArray()
代替 get()
来获取结果数组。