gregpriday/laravel-serper

This is my package laravel-serper

0.1 2024-02-29 17:10 UTC

This package is auto-updated.

Last update: 2024-05-15 10:04:49 UTC


README

Introduction

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.

Features

  • 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.

Installation

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"

Configuration

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', ''),
];

Usage

The Laravel Serper package provides a simple API to perform search and news queries. Here's how you can use it:

Performing a Search

To perform a search, use the Serper::search method:

use GregPriday\LaravelSerper\Facades\Serper;

$results = Serper::search('Laravel');

Retrieving News Results

To retrieve news results, specify the type as 'news' in the search method:

$newsResults = Serper::search('Laravel', 10, 'news');

Performing Multiple Searches

To perform multiple searches at once, use the Serper::searchMulti method:

$queries = ['Laravel', 'PHP'];
$results = Serper::searchMulti($queries, 10, 'search');

Testing

This package comes with a suite of PHPUnit tests. To run the tests, use the following command:

vendor/bin/phpunit

Contribution

Contributions are welcome! Please feel free to submit pull requests or open issues on the GitHub repository.

License

The Laravel Serper package is open-sourced software licensed under the MIT license.