shweshi/laravel-unsplash-wrapper

Unsplash 的 Laravel 封装

4.0.0 2021-09-13 19:47 UTC

This package is auto-updated.

Last update: 2024-09-05 15:12:57 UTC


README

Latest Version on Packagist Scrutinizer Code Quality StyleCI Build Status Total Downloads FOSSA Status

Unsplash 的 Laravel 封装。

安装

通过 Composer

$ composer require shweshi/laravel-unsplash-wrapper

如果您没有运行 Laravel 5.5(或更高版本),则在 config/app.php 中添加服务提供者

shweshi\LaravelUnsplashWrapper\Providers\UnsplashServiceProvider::class,
shweshi\LaravelUnsplashWrapper\Providers\UnsplashSearchServiceProvider::class,
shweshi\LaravelUnsplashWrapper\Providers\UnsplashUsersServiceProvider::class,
shweshi\LaravelUnsplashWrapper\Providers\UnsplashPhotosServiceProvider::class,
shweshi\LaravelUnsplashWrapper\Providers\UnsplashCollectionsServiceProvider::class,

如果您在 Laravel 5.5+ 上运行该软件包,则包自动发现会处理添加服务提供者的魔法。

接下来在 config/app.php 中的别名数组下添加

'UnsplashSearch' => shweshi\LaravelUnsplashWrapper\Facades\UnsplashSearchFacade::class,
'UnsplashUsers' => shweshi\LaravelUnsplashWrapper\Facades\UnsplashUsersFacade::class,
'UnsplashPhotos' => shweshi\LaravelUnsplashWrapper\Facades\UnsplashPhotosFacade::class,
'UnsplashCollections' => shweshi\LaravelUnsplashWrapper\Facades\UnsplashCollectionsFacade::class,

您必须发布配置,以提供自己的服务提供者模板。

$ php artisan vendor:publish --provider="shweshi\LaravelUnsplashWrapper\Providers\UnsplashServiceProvider"

更新生成的 app/config/unsplash.php 配置文件中的设置。

return [
    'ApplicationID' => 'YOUR APPLICATION ACCES KEY HERE',
];

用法

有关参数和其他信息的文档,请参阅 unsplash 文档

方法列表

照片

$photos        = UnsplashPhotos::photos([]);          // list of all photos
$photo         = UnsplashPhotos::single($id, $params);     // single photo
$statistic     = UnsplashPhotos::statistic($id, $params);  // single photo statistics
$downloadUrl   = UnsplashPhotos::download($id, $params);   // single photo download link
$curatedPhotos = UnsplashPhotos::curated($params);         // list of curated photos
$randomPhoto   = UnsplashPhotos::random($params);          // random photo

用户

use UnsplashUsers;

$user         = UnsplashUsers::profile($username, $params);      // single user
$portfolio    = UnsplashUsers::portfolio($username);             // single user's portfolio
$photos       = UnsplashUsers::photos($username, $params);       // single user's photos
$photos       = UnsplashUsers::likes($username, $params);        // single user's likes
$collections  = UnsplashUsers::collections($username, $params);  // single user's collections
$statistics   = UnsplashUsers::statistics($username, $params);   // single user's statistics

收藏集

use UnsplashCollections;

$collection  = UnsplashCollections::collections($params);    // list of all collections
$collection  = UnsplashCollections::single($id, $params);    // single collections
$photos      = UnsplashCollections::photos($id, $params);    // collection photos
$statistic   = UnsplashCollections::statistic($id, $params); // single collections statistics
$collection  = UnsplashCollections::curated($params);        // list of curated collections
$collection  = UnsplashCollections::related($id, $params);   // list of related collections
$collection  = UnsplashCollections::featured($params);       // list of featured collections

搜索

use UnsplashSearch;

$photos     = UnsplashSearch::photo($query, $params);
$collection = UnsplashSearch::collection($query, $params);
$user       = UnsplashSearch::user($query, $params);

示例

echo UnsplashPhotos::photos(['page' => 1, 'order_by' => 'oldest']);

将得到类似以下内容

ixlib=rb-0.3.5\u0026q=80\u0026fm=jpg\u0026crop=faces\u0026cs=tinysrgb\u0026fit=crop\u0026h=64\u0026w=64\u0026s=4ddd6656ddd74206872f45c033371087","large":"https://images.unsplash.com/profile-1441298310363-3eb4b1feb829?
.....

您需要对其进行格式化

贡献

有关详细信息,请参阅 贡献指南行为准则

许可证

FOSSA Status

支持

Buy Me A Coffee

编码愉快!