定制 gabrielesbaiz/unsplash-toolkit 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

gabrielesbaiz/unsplash-toolkit

最新稳定版本:1.1.1

Composer 安装命令:

composer require gabrielesbaiz/unsplash-toolkit

包简介

A lightweight helper package to handle Unsplash photos

README 文档

README

Latest Version on Packagist Total Downloads

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.

统计信息

  • 总下载量: 957
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-03-02