1. Go to this page and download the library: Download bugo/pexels-laravel library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
bugo / pexels-laravel example snippets
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' => [...],
],
];
use Bugo\PexelsLaravel\Services\PexelsService;
$pexelsService = app(PexelsService::class);
// Get a random image by search query
$image = $pexelsService->getRandomImage('nature');