The Laravel Serper package is a simple, efficient wrapper around the Serper.dev API, designed to integrate seamlessly with Laravel applications. It provides a fluent, expressive interface to perform searches and retrieve news results from Google via Serper.dev, making it easier for developers to include search functionalities in their Laravel applications.
- Easy-to-use facade for performing searches and retrieving news results.
- Support for single and multiple queries with customizable parameters.
- Integration with Laravel's service container for easy configuration and extension.
- Utilizes GuzzleHttp for efficient HTTP requests.
- Includes a suite of unit tests for reliability and maintainability.
To install the Laravel Serper package, run the following command in your terminal:
composer require gregpriday/laravel-serper
After installation, publish the package's configuration file by running:
php artisan vendor:publish --provider="GregPriday\LaravelSerper\SerperServiceProvider"
Before using the Serper package, you must obtain an API key from Serper.dev and add it to your .env
file:
SERPER_API_KEY=your_serper_dev_api_key
Then, configure your API key in the config/serper.php
configuration file:
return [
'key' => env('SERPER_API_KEY', ''),
];
The Laravel Serper package provides a simple API to perform search and news queries. Here's how you can use it:
To perform a search, use the Serper::search
method:
use GregPriday\LaravelSerper\Facades\Serper;
$results = Serper::search('Laravel');
To retrieve news results, specify the type as 'news' in the search
method:
$newsResults = Serper::search('Laravel', 10, 'news');
To perform multiple searches at once, use the Serper::searchMulti
method:
$queries = ['Laravel', 'PHP'];
$results = Serper::searchMulti($queries, 10, 'search');
This package comes with a suite of PHPUnit tests. To run the tests, use the following command:
vendor/bin/phpunit
Contributions are welcome! Please feel free to submit pull requests or open issues on the GitHub repository.
The Laravel Serper package is open-sourced software licensed under the MIT license.