LaravelPixabay is a Laravel package that simplifies the process of interacting with the Pixabay API. It provides a way to search and retrieve images and videos from the Pixabay platform with minimal effort. This package includes various customizable options like image/video type, categories, order, page results, and more.
- PHP 8.0 or higher
- Laravel 9.x or higher
- Pixabay API key (you can get this from Pixabay's Developer page)
If you find my packages useful, consider buying me a coffee to support further development.
You can install the package via composer:
composer require joukhar/laravel-pixabay
You can publish the config file or add pixabay service to (config/services.php) file:
php artisan vendor:publish --tag="laravel-pixabay-config"
Configuration file (config/pixabay.php):
return [
'key' => env('PIXABAY_API_KEY'),
];
Then add your Pixabay API key to the .env file:
PIXABAY_KEY=your_pixabay_api_key
$laravelPixabay = new Joukhar\LaravelPixabay();
$laravelPixabay->getImages();
$laravelPixabay = new Joukhar\LaravelPixabay();
$laravelPixabay->getImages(id:"< IMAGE ID HERE >");
use Joukhar\LaravelPixabay\Enums\PixabayImageType;
$laravelPixabay = new Joukhar\LaravelPixabay();
$laravelPixabay->getImages(type: PixabayImageType::ILLUSTRATION );
$laravelPixabay = new Joukhar\LaravelPixabay();
$laravelPixabay->getVideos();
use Joukhar\LaravelPixabay\Enums\PixabayVideoType;
$laravelPixabay = new Joukhar\LaravelPixabay();
$laravelPixabay->getVideos(type: PixabayVideoType::ANIMATION);
$laravelPixabay = new Joukhar\LaravelPixabay();
$laravelPixabay->getVideos(id:"< VIDEO ID HERE >");
You can customize your queries using several configuration methods provided by the LaravelPixabay
class.
Set Current Page
You can specify which page of results to fetch using setCurrentPage()
:
$pixabay->setCurrentPage(2);
Set Maximum Results Per Page
The number of results per page can be adjusted using setMaxResults()
:
$pixabay->setMaxResults(50);
Enable Safe Search
To filter out adult content, use setSafeSearch()
:
$pixabay->setSafeSearch(true);
Only Editor's Choice
You can request only editor's choice images or videos using setOnlyEditorChoice()
:
$pixabay->setOnlyEditorChoice(true);
Set Category
To fetch resources of a specific category, use setCategory()
:
use Joukhar\LaravelPixabay\Enums\PixabayCategory;
$pixabay->setCategory(PixabayCategory::NATURE);
Set Order
To order results by popularity, latest, or custom order, use setOrder()
:
$pixabay->setOrder('latest');
Set Minimum Dimensions
You can set the minimum width and height for the images/videos to be returned using setDimentions()
:
$pixabay->setDimentions(800, 600);
use Joukhar\LaravelPixabay\LaravelPixabay;
use Joukhar\LaravelPixabay\Enums\PixabayCategory;
use Joukhar\LaravelPixabay\Enums\PixabayImageType;
$pixabay = new LaravelPixabay();
$photos = $pixabay
->setCategory(PixabayCategory::NATURE)
->setMaxResults(10)
->setSafeSearch(true)
->getImages(null, PixabayImageType::PHOTO);
If there is an issue with the API request (e.g., invalid API key, request failure), the package throws an Exception
with a detailed error message.
try {
$images = $pixabay->getImages();
} catch (Exception $e) {
echo 'Error: ' . $e->getMessage();
}
composer test
Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
Please review our security policy on how to report security vulnerabilities.
The MIT License (MIT). Please see License File for more information.