Download the PHP package xchimx/laravel-unsplash without Composer
On this page you can find all versions of the php package xchimx/laravel-unsplash. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download xchimx/laravel-unsplash
More information about xchimx/laravel-unsplash
Files in xchimx/laravel-unsplash
Package laravel-unsplash
Short Description Laravel package for easy integration with the Unsplash API. It allows you to use the Unsplash API in your Laravel applications to fetch photos, collections, and user data.
License MIT
Homepage https://www.schottstaedt.net
Informations about the package laravel-unsplash
About Laravel-Unsplash
A Laravel package for easy integration with the Unsplash API. It allows you to use the Unsplash API in your Laravel applications to fetch photos, collections, and user data.
---
- About Laravel-Unsplash
- Installation
- Usage
- Basic Usage
- Using the Facade
- UnsplashService Methods
- Controller Examples
- 1. searchPhotos
- 2. searchPhotosAdvanced
- 3. getPhoto
- 4. getRandomPhoto
- 5. getPhotoDownloadLink
- 6. listCollections
- 7. getCollection
- 8. getUser
- 9. getUserPhotos
- 10. searchCollections
- 11. withOptions
- Rate Limiting Middleware
- Configuration
- Usage
- Error Handling
- Notes on the Unsplash API
- License
Installation
You can install the package via composer:
Publish the config file using the artisan CLI tool:
finally set the API Key in your ENV file:
Optional Rate Limiting settings in ENV file:
Usage
Basic Usage
You can use the UnsplashService in your controllers by injecting it via Dependency Injection:
Using the Facade
Alternatively, you can use the provided Unsplash facade:
UnsplashService Methods
The UnsplashService provides the following methods:
- searchPhotos($query, $perPage = 10, $page = 1)
- searchPhotosAdvanced(array $params)
- getPhoto($id)
- getRandomPhoto(array $params = [])
- getPhotoDownloadLink($id)
- listCollections($perPage = 10, $page = 1)
- getCollection($id)
- getUser($username)
- getUserPhotos($username, $perPage = 10, $page = 1)
- searchCollections($query, $perPage = 10, $page = 1)
- withOptions(array $options)
Controller Examples
Here are comprehensive controller examples showing how to use the various methods of the UnsplashService in your Laravel controllers.
1. searchPhotos
Blade View:
2. searchPhotosAdvanced
3. getPhoto
Blade View:
4. getRandomPhoto
Blade View:
5. getPhotoDownloadLink
6. listCollections
Blade View:
7. getCollection
Blade View:
8. getUser
9. getUserPhotos
Blade View:
10. searchCollections
Blade View:
11. withOptions
Blade View:
Rate Limiting Middleware
This package includes middleware to monitor and handle the Unsplash API rate limits. The middleware is enabled by default and can be customized in the configuration options.
Configuration
The rate limiting settings are located in config/unsplash.php:
- enabled: Enables or disables the rate limiting middleware.
- threshold: The threshold for remaining requests at which the middleware intervenes.
Usage
To use the middleware in your routes, add it as follows:
Error Handling
It's important to handle errors during API calls, especially when communicating with external services.
Notes on the Unsplash API
- Rate Limits: The Unsplash API has rate limits. Be sure to monitor the number of requests and use the provided middleware.
- Attribution: When using photos, you must credit the photographers according to Unsplash's guidelines.
- API Documentation: For more details, refer to the Unsplash API Documentation.
License
This package is released under the MIT License.