### Install Laravel Unsplash Package
Source: https://github.com/marksitko/laravel-unsplash/blob/master/README.md
Instructions for installing the Laravel Unsplash package using Composer. This command adds the package to your project and handles initial setup.
```bash
composer require marksitko/laravel-unsplash
```
--------------------------------
### Install Laravel Unsplash Package
Source: https://context7.com/marksitko/laravel-unsplash/llms.txt
Instructions for installing the Laravel Unsplash package using Composer and publishing its configuration and migration files. This sets up the package for use in a Laravel project.
```bash
composer require marksitko/laravel-unsplash
php artisan vendor:publish --tag=config
php artisan vendor:publish --tag=migrations
php artisan migrate
```
--------------------------------
### Fetch User Data (PHP)
Source: https://github.com/marksitko/laravel-unsplash/blob/master/README.md
Examples of retrieving various data related to Unsplash users, including their profile, portfolio, photos, likes, collections, and statistics.
```php
$user = Unsplash::user($username)->toJson();
$userPortfolio = Unsplash::userPortfolio($username)->toJson();
$userPhotos = Unsplash::userPhotos($username)->toJson();
$userLikes = Unsplash::userLikes($username)->toJson();
$userCollections = Unsplash::userCollections($username)->toJson();
$userStatistics = Unsplash::userStatistics($username)->toJson();
```
--------------------------------
### List and Retrieve Photos
Source: https://context7.com/marksitko/laravel-unsplash/llms.txt
Code examples for listing all photos with pagination, retrieving a specific photo by ID, getting photo statistics, and tracking photo downloads using the Laravel Unsplash package. Also shows how to get the response in different formats.
```php
use MarkSitko\LaravelUnsplash\Facades\Unsplash;
// List all photos with pagination
$photos = Unsplash::photos()
->page(1)
->perPage(20)
->orderBy('latest') // latest, oldest, popular
->toJson();
// Get a specific photo by ID
$photo = Unsplash::photo('photo_id_here')->toJson();
// Get photo statistics (downloads, views, likes)
$stats = Unsplash::photosStatistics('photo_id_here')
->resolution('days')
->quantity(30)
->toJson();
// Track a photo download (required by Unsplash API guidelines)
$download = Unsplash::trackPhotoDownload('photo_id_here')->toJson();
// Get response as different formats
$response = Unsplash::photos()->get(); // Full Guzzle Response
$json = Unsplash::photos()->toJson(); // Decoded JSON object
$array = Unsplash::photos()->toArray(); // PHP array
$collection = Unsplash::photos()->toCollection(); // Laravel Collection
```
--------------------------------
### Fetch Photos (PHP)
Source: https://github.com/marksitko/laravel-unsplash/blob/master/README.md
Examples of fetching lists of photos, a single photo by ID, photo statistics, and tracking photo downloads using the Unsplash API via the package.
```php
$photos = Unsplash::photos()->toJson();
$photo = Unsplash::photo($id)->toJson();
$photosStatistics = Unsplash::photosStatistics($id)->toJson();
$trackPhotoDownload = Unsplash::trackPhotoDownload($id)->toJson();
```
--------------------------------
### Manage Collections (PHP)
Source: https://github.com/marksitko/laravel-unsplash/blob/master/README.md
Examples for interacting with Unsplash collections, including listing collections, fetching featured collections, showing a specific collection, its photos, and related collections.
```php
$collectionsList = Unsplash::collectionsList()
->page($pageNumber)
->perPage($itemsPerPage)
->toJson();
$featuredCollection = Unsplash::featuredCollection()
->page($pageNumber)
->perPage($itemsPerPage)
->toJson();
$showCollection = Unsplash::showCollection()
->id($collectionId)
->toJson();
$showCollectionPhotos = Unsplash::showCollectionPhotos()
->id($collectionId)
->toJson();
$showCollectionRelatedCollections = Unsplash::showCollectionRelatedCollections()
->id($collectionId)
->toJson();
```
--------------------------------
### Fetch Statistics (PHP)
Source: https://github.com/marksitko/laravel-unsplash/blob/master/README.md
Examples for retrieving overall and monthly statistics from Unsplash using the package. These endpoints provide aggregated data.
```php
$totalStats = Unsplash::totalStats()->toJson();
$monthlyStats = Unsplash::monthlyStats()->toJson();
```
--------------------------------
### Associate and Retrieve Unsplash Assets with HasUnsplashables (PHP)
Source: https://github.com/marksitko/laravel-unsplash/blob/master/README.md
These PHP examples show how to use the `HasUnsplashables` trait. The first example stores a random Unsplash photo and saves it to a morphToMany relation on the User model. The second example retrieves all Unsplash assets associated with a specific user.
```php
// store the unsplash asset in a morphToMany relation
$unsplashAsset = Unsplash::randomPhoto()->store();
User::unsplash()->save($unsplashAsset);
// retrive all related unsplash assets
User::find($userId)->unsplash();
```
--------------------------------
### Fetch Random Photos (PHP)
Source: https://github.com/marksitko/laravel-unsplash/blob/master/README.md
Example of fetching random photos from Unsplash using the package. Demonstrates chaining methods to specify orientation, terms, and count, and outputting as JSON or storing the image.
```php
// Returns the http response body.
$twoRandomPhotosOfSomePeoples = Unsplash::randomPhoto()
->orientation('portrait')
->term('people')
->count(2)
->toJson();
// Store the image in on your provided disc
$theNameFromTheStoredPhoto = Unsplash::randomPhoto()
->orientation('landscape')
->term('music')
->randomPhoto()
->store();
];
```
--------------------------------
### Interact with UnsplashAsset Model (PHP)
Source: https://github.com/marksitko/laravel-unsplash/blob/master/README.md
This PHP code shows how to use the `UnsplashAsset` Eloquent model. You can store a random photo and get the database record, or retrieve an existing stored asset by its ID. This model provides an interface for managing persisted Unsplash assets.
```php
// Returns the created unsplash asset record
$databaseRecord = UnsplashAsset::api()->randomPhoto()->store();
// Get an stored unsplash asset
$unsplashAsset = UnsplashAsset::find($id);
```
--------------------------------
### Publish Configuration and Migrations
Source: https://github.com/marksitko/laravel-unsplash/blob/master/README.md
Commands to publish the package's configuration file and migration files. Publishing migrations is necessary for database integration.
```bash
php artisan vendor:publish --tag=config
```
```bash
php artisan vendor:publish --tag=migrations
```
--------------------------------
### Publish and Run Migrations for Unsplash Data Storage
Source: https://github.com/marksitko/laravel-unsplash/blob/master/README.md
These bash commands are used to publish the package's migration files and then run them to create the necessary database tables for storing Unsplash image information. This is a prerequisite for persisting image data.
```bash
$ php artisan vendor:publish --tag=migrations
$ php artisan migrate
```
--------------------------------
### Search Photos, Collections, and Users (PHP)
Source: https://github.com/marksitko/laravel-unsplash/blob/master/README.md
Demonstrates how to perform searches on Unsplash for photos, collections, and users. Allows filtering by various parameters like terms, color, orientation, and query.
```php
$search = Unsplash::search()
->term('buildings')
->color('black_and_white')
->orientation('squarish')
->toJson();
$searchCollections = Unsplash::searchCollections()
->query('events')
->page($pageNumber)
->toJson();
$searchUsers = Unsplash::searchUsers()
->query('search_term')
->toJson();
```
--------------------------------
### Work with Topics (PHP)
Source: https://github.com/marksitko/laravel-unsplash/blob/master/README.md
Code snippets for retrieving information about Unsplash topics, including listing all topics and fetching photos associated with a specific topic.
```php
$topicsList = Unsplash::topicsList()
->page($pageNumber)
->perPage($itemsPerPage)
->toJson();
$showTopic = Unsplash::showTopic()
->id($topicIdOrSlug)
->toJson();
$showTopicPhotos = Unsplash::showTopicPhotos()
->id($topicIdOrSlug)
->toJson();
```
--------------------------------
### Register Service Provider and Facade (Manual)
Source: https://github.com/marksitko/laravel-unsplash/blob/master/README.md
Manual registration of the Unsplash Service Provider and Facade in Laravel's config/app.php file. This is an alternative to automatic package discovery.
```php
'providers' => [
//...
MarkSitko\LaravelUnsplash\UnsplashServiceProvider::class,
];
```
```php
'aliases' => [
//...
'Unsplash' => MarkSitko\LaravelUnsplash\Facades\Unsplash::class,
];
```
--------------------------------
### Optional Unsplash Configurations
Source: https://github.com/marksitko/laravel-unsplash/blob/master/README.md
Optional settings for the Laravel Unsplash package, including whether to store images in the database and the storage disk to use.
```env
# default is false
UNSPLASH_STORE_IN_DATABASE=BOOLEAN
```
```env
# default is local
UNSPLASH_STORAGE_DISC=YOUR_STORAGE_DISC
```
--------------------------------
### Configure .env for Database Storage
Source: https://github.com/marksitko/laravel-unsplash/blob/master/README.md
Add this line to your .env file to enable the storage of Unsplash image data in your database. When set to true, the `store()` method will persist image details like ID, name, author name, and author link.
```env
UNSPLASH_STORE_IN_DATABASE=true
```
--------------------------------
### Configure Unsplash API Access Key
Source: https://github.com/marksitko/laravel-unsplash/blob/master/README.md
Setting the Unsplash API access key in the .env file. This is a mandatory step for the package to authenticate with the Unsplash API.
```env
UNSPLASH_ACCESS_KEY=YOUR_GENERATED_API_KEY_FROM_UNSPLASH
```
--------------------------------
### Retrieve Platform Statistics with Laravel Unsplash
Source: https://context7.com/marksitko/laravel-unsplash/llms.txt
Fetch overall Unsplash platform statistics, including total counts of photos, downloads, views, and photographers, as well as monthly activity data for the past 30 days. This PHP code uses the Laravel Unsplash facade.
```php
use MarkSitko\LaravelUnsplash\Facades\Unsplash;
// Get total platform statistics
$total = Unsplash::totalStats()->toJson();
// Returns: total photos, downloads, views, photographers, etc.
// Get monthly statistics (past 30 days)
$monthly = Unsplash::monthlyStats()->toJson();
// Returns: downloads, views, new photos for the past month
```
--------------------------------
### Configure Unsplash API Credentials
Source: https://context7.com/marksitko/laravel-unsplash/llms.txt
Configuration settings for the Laravel Unsplash package, to be added to the .env file. This includes the Unsplash API access key and optional settings for database storage and storage disk.
```dotenv
UNSPLASH_ACCESS_KEY=your_unsplash_api_key
UNSPLASH_STORE_IN_DATABASE=true // optional, default: false
UNSPLASH_STORAGE_DISK=public // optional, default: local
```
--------------------------------
### Retrieve Random Photos with Filters
Source: https://context7.com/marksitko/laravel-unsplash/llms.txt
Demonstrates how to retrieve random photos from Unsplash using the Laravel Unsplash package. Supports filtering by orientation, search terms, collections, count, featured status, and storing photos to disk.
```php
use MarkSitko\LaravelUnsplash\Facades\Unsplash;
// Get a single random portrait photo related to "nature"
$photo = Unsplash::randomPhoto()
->orientation('portrait')
->term('nature')
->toJson();
// Get multiple random photos
$photos = Unsplash::randomPhoto()
->orientation('landscape')
->term('technology')
->count(5)
->featured(true)
->toJson();
// Get random photo from specific collections
$photo = Unsplash::randomPhoto()
->collections('123,456,789')
->username('unsplash')
->toArray();
// Store a random photo to disk (returns filename or UnsplashAsset model)
$storedPhoto = Unsplash::randomPhoto()
->orientation('squarish')
->term('office')
->store('my-photo-name', 'regular'); // size: raw, full, regular, small, thumb
```
--------------------------------
### Store Photos Locally with UnsplashAsset Model in Laravel
Source: https://context7.com/marksitko/laravel-unsplash/llms.txt
Store photos locally using the UnsplashAsset model, which automatically handles copyright tracking. This feature requires running package migrations. The code demonstrates storing random photos, accessing asset properties, generating copyright attribution, and using the UnsplashAsset model for API access and querying.
```php
use MarkSitko\LaravelUnsplash\Facades\Unsplash;
use MarkSitko\LaravelUnsplash\Models\UnsplashAsset;
// Store a photo (returns UnsplashAsset when database storage is enabled)
$asset = Unsplash::randomPhoto()
->term('workspace')
->store('custom-name', 'regular');
// Access stored asset properties
echo $asset->unsplash_id; // Original Unsplash photo ID
echo $asset->name; // Stored filename
echo $asset->author; // Photographer name
echo $asset->author_link; // Link to photographer's Unsplash profile
// Generate copyright attribution HTML
echo $asset->getFullCopyrightLink();
// Output: Photo by Author Name on Unsplash
// Use UnsplashAsset model directly for API access
$asset = UnsplashAsset::api()->randomPhoto()->store();
// Query stored assets
$asset = UnsplashAsset::find($id);
$allAssets = UnsplashAsset::all();
// Delete asset (automatically removes file from storage)
$asset->delete();
```
--------------------------------
### Store Unsplash Photo with Database Record (PHP)
Source: https://github.com/marksitko/laravel-unsplash/blob/master/README.md
This PHP code snippet demonstrates how to store a random Unsplash photo and retrieve the created database record. The `store()` method on the Unsplash client handles both downloading the image and saving its metadata to the database.
```php
// Returns the created unsplash asset record
$databaseRecord = Unsplash::randomPhoto()->store();
```
--------------------------------
### Manage Unsplash Collections with Laravel Unsplash
Source: https://context7.com/marksitko/laravel-unsplash/llms.txt
Browse and retrieve Unsplash collections, including featured collections, collection details, photos within collections, and related collections. This PHP code utilizes the Laravel Unsplash facade to interact with the Unsplash API.
```php
use MarkSitko\LaravelUnsplash\Facades\Unsplash;
// List all collections
$collections = Unsplash::collectionsList()
->page(1)
->perPage(20)
->toJson();
// List featured collections
$featured = Unsplash::featuredCollection()
->page(1)
->perPage(10)
->toJson();
// Get a specific collection
$collection = Unsplash::showCollection(123)->toJson();
// Get photos from a collection
$photos = Unsplash::showCollectionPhotos(123)
->page(1)
->perPage(15)
->toJson();
// Get related collections
$related = Unsplash::showCollectionRelatedCollections(123)->toJson();
```
--------------------------------
### Associate Unsplash Assets with Eloquent Models using HasUnsplashables Trait
Source: https://context7.com/marksitko/laravel-unsplash/llms.txt
Integrate Unsplash assets with any Eloquent model using the polymorphic relationship provided by the HasUnsplashables trait. The code demonstrates associating and retrieving assets with a User model, including saving single or multiple assets, detaching assets, and automatic cleanup upon model deletion.
```php
use Illuminate\Foundation\Auth\User as Authenticatable;
use MarkSitko\LaravelUnsplash\Traits\HasUnsplashables;
use MarkSitko\LaravelUnsplash\Facades\Unsplash;
class User extends Authenticatable
{
use HasUnsplashables;
// Your model code...
}
// Store and associate an unsplash asset with a user
$user = User::find(1);
$asset = Unsplash::randomPhoto()->term('avatar')->store();
$user->unsplash()->save($asset);
// Associate multiple assets
$assets = collect([
Unsplash::randomPhoto()->term('banner')->store(),
Unsplash::randomPhoto()->term('background')->store(),
]);
$user->unsplash()->saveMany($assets);
// Retrieve all associated unsplash assets
$userAssets = $user->unsplash;
// Detach an asset from user
$user->unsplash()->detach($asset->id);
// Assets are automatically detached when the model is deleted
$user->delete(); // Unsplash relationships are cleaned up
```
--------------------------------
### Browse Unsplash Topics with Laravel Unsplash
Source: https://context7.com/marksitko/laravel-unsplash/llms.txt
Access Unsplash topics, which are curated photo categories. This PHP code allows listing all topics, retrieving specific topic details by ID or slug, and fetching photos associated with a topic. It uses the Laravel Unsplash facade.
```php
use MarkSitko\LaravelUnsplash\Facades\Unsplash;
// List all topics
$topics = Unsplash::topicsList()
->page(1)
->perPage(20)
->ids('topic-id-1,topic-id-2') // optional: filter by specific IDs
->orderBy('position')
->toJson();
// Get a specific topic by ID or slug
$topic = Unsplash::showTopic('nature')->toJson();
// Get photos from a topic
$photos = Unsplash::showTopicPhotos('nature')
->page(1)
->perPage(15)
->orderBy('latest')
->toJson();
```
--------------------------------
### Access User Public Profiles and Content with Laravel Unsplash
Source: https://context7.com/marksitko/laravel-unsplash/llms.txt
Retrieve various user-related data from Unsplash, including public profiles, portfolios, photos, liked images, collections, and statistics. This functionality requires the Laravel Unsplash package and uses its facade for API interactions.
```php
use MarkSitko\LaravelUnsplash\Facades\Unsplash;
// Get user public profile
$user = Unsplash::user('username')->toJson();
// Get user portfolio link
$portfolio = Unsplash::userPortfolio('username')->toJson();
// List user's uploaded photos
$photos = Unsplash::userPhotos('username')
->page(1)
->perPage(20)
->orderBy('latest')
->toJson();
// List photos liked by user
$likes = Unsplash::userLikes('username')
->page(1)
->perPage(10)
->toJson();
// List user's collections
$collections = Unsplash::userCollections('username')->toJson();
// Get user statistics
$stats = Unsplash::userStatistics('username')
->resolution('days')
->quantity(30)
->toJson();
```
--------------------------------
### Use HasUnsplashables Trait on a Model (PHP)
Source: https://github.com/marksitko/laravel-unsplash/blob/master/README.md
This PHP code demonstrates how to use the `HasUnsplashables` trait on a custom Eloquent model, such as the `User` model. By using this trait, your model gains the ability to associate and manage Unsplash assets through morphToMany relationships.
```php
use Illuminate\Foundation\Auth\User as Authenticatable;
use MarkSitko\LaravelUnsplash\Traits\HasUnsplashables;
class User extends Authenticatable
{
use HasUnsplashables;
// ...
}
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.