PHPackages                             bugo/pexels-laravel - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. bugo/pexels-laravel

ActiveLibrary

bugo/pexels-laravel
===================

Laravel Pexels API integration with rate limiting

0.1.1(1mo ago)06MITPHPPHP ^8.2CI passing

Since Dec 3Pushed 1mo agoCompare

[ Source](https://github.com/dragomano/pexels-laravel)[ Packagist](https://packagist.org/packages/bugo/pexels-laravel)[ RSS](/packages/bugo-pexels-laravel/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (8)Versions (3)Used By (0)

Pexels Laravel
==============

[](#pexels-laravel)

A Laravel package for integrating Pexels API with built-in rate limiting, caching, and fallback images.

Features
--------

[](#features)

- Easy integration with Pexels API
- Built-in rate limiting (hourly and monthly)
- Configurable caching
- Automatic fallback images when limits are exceeded
- Usage statistics command

Requirements
------------

[](#requirements)

- PHP 8.2+
- Laravel 11+

Installation
------------

[](#installation)

### 1. Install via Composer

[](#1-install-via-composer)

```
composer require bugo/pexels-laravel
```

### 2. Publish Configuration

[](#2-publish-configuration)

```
php artisan vendor:publish --tag=pexels-config
```

This will create `config/pexels.php` in your application.

### 3. Add API Key to `.env`

[](#3-add-api-key-to-env)

```
PEXELS_API_KEY=your_api_key
```

Get your free API key at

Configuration
-------------

[](#configuration)

The `config/pexels.php` file contains all configuration options:

```
return [
    // Your Pexels API key
    'api_key' => env('PEXELS_API_KEY'),

    // Rate limits (adjust based on your Pexels plan)
    'rate_limits' => [
        'hourly' => env('PEXELS_HOURLY_LIMIT', 200),
        'monthly' => env('PEXELS_MONTHLY_LIMIT', 20000),
    ],

    // Cache settings
    'cache' => [
        'enabled' => env('PEXELS_CACHE_ENABLED', true),
        'ttl' => env('PEXELS_CACHE_TTL', 3600), // seconds
    ],

    // Fallback images when API limits are exceeded
    'fallback_images' => [
        'nature' => [...],
        'technology' => [...],
        'food' => [...],
    ],
];
```

### Environment Variables

[](#environment-variables)

```
# Required
PEXELS_API_KEY=your_api_key

# Optional (with defaults)
PEXELS_CACHE_ENABLED=true
PEXELS_CACHE_TTL=3600
PEXELS_HOURLY_LIMIT=200
PEXELS_MONTHLY_LIMIT=20000
```

Usage
-----

[](#usage)

### Basic Usage

[](#basic-usage)

```
use Bugo\PexelsLaravel\Services\PexelsService;

$pexelsService = app(PexelsService::class);

// Get a random image by search query
$image = $pexelsService->getRandomImage('nature');
```

### Response Format

[](#response-format)

It returns an array with the following structure:

```
[
    'url' => 'https://images.pexels.com/photos/...',
    'photographer' => 'John Doe',
    'photographer_url' => 'https://www.pexels.com/@johndoe',
    'pexels_url' => 'https://www.pexels.com/photo/...',
    'alt' => 'Image description',
    'query' => 'nature',
    'from_api' => true, // false if fallback image
]
```

### In Controllers

[](#in-controllers)

```
namespace App\Http\Controllers;

use Bugo\PexelsLaravel\Services\PexelsService;

class ImageController extends Controller
{
    public function random(PexelsService $pexelsService)
    {
        $image = $pexelsService->getRandomImage('technology');

        return view('image', ['image' => $image]);
    }
}
```

### In Blade Templates

[](#in-blade-templates)

```

@if(!empty($image['photographer']))

    Photo by

        {{ $image['photographer'] }}

    on
    Pexels

@endif
```

### In Database Seeders

[](#in-database-seeders)

```
use Bugo\PexelsLaravel\Services\PexelsService;

class ArticleSeeder extends Seeder
{
    public function run(): void
    {
        $pexelsService = app(PexelsService::class);

        $queries = ['nature', 'technology', 'business', 'travel'];

        for ($i = 0; $i < 50; $i++) {
            $query = $queries[array_rand($queries)];
            $image = $pexelsService->getRandomImage($query);

            Article::create([
                'title' => fake()->sentence,
                'content' => fake()->paragraphs(3, true),
                'image_url' => $image['url'],
                'image_alt' => $image['alt'],
                'image_photographer' => $image['photographer'],
                'image_photographer_url' => $image['photographer_url'],
            ]);
        }
    }
}
```

### Usage Statistics

[](#usage-statistics)

Check your current API usage:

```
php artisan pexels:usage
```

Output example:

```
Pexels API Usage Statistics

+---------+------+-------+-----------+------------+
| Period  | Used | Limit | Remaining | Percentage |
+---------+------+-------+-----------+------------+
| Hourly  | 45   | 180   | 135       | 25%        |
| Monthly | 3420 | 19000 | 15580     | 18%        |
+---------+------+-------+-----------+------------+

```

###  Health Score

36

—

LowBetter than 82% of packages

Maintenance89

Actively maintained with recent releases

Popularity5

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity38

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~108 days

Total

2

Last Release

58d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/6ef0dd570abdd5696bf5ba391bcd00ed0bb0ac5d1a5654785e8f204d548ddfc0?d=identicon)[Bugo](/maintainers/Bugo)

---

Top Contributors

[![dragomano](https://avatars.githubusercontent.com/u/229402?v=4)](https://github.com/dragomano "dragomano (6 commits)")

---

Tags

laravel-packagepexelspexels-apipexels laravelpexels api service

###  Code Quality

TestsPest

Static AnalysisRector

### Embed Badge

![Health badge](/badges/bugo-pexels-laravel/health.svg)

```
[![Health](https://phpackages.com/badges/bugo-pexels-laravel/health.svg)](https://phpackages.com/packages/bugo-pexels-laravel)
```

###  Alternatives

[fumeapp/modeltyper

Generate TypeScript interfaces from Laravel Models

196277.9k](/packages/fumeapp-modeltyper)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
