PHP code example of iblank / laravel-gov-search

1. Go to this page and download the library: Download iblank/laravel-gov-search 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/ */

    

iblank / laravel-gov-search example snippets


'DEFAULTS' => array(
    'highlight' => true,
    'limit' => 20, // 1 to 999
    'sort' => 'relevance' // or 'date'
)

/**
 * Returns PHP object of search results
 * @param $search (string) - what to search for
 * @param $options (array) - set an 'offset' index and/or override any of the defaults set in the config file
 * @return (object) - PHP object (details below)
 */
$apiResult = GovSearch::search($search, $options);

// Set Defaults
$search = 'Medal of Honor';
$options = array(
    'offset' => 0,
    'limit' => 25
);

// Make initial call
$apiResult = GovSearch::search($search, $options);

// Set total results
$totalResults = $apiResult['total'];

// Set total pages
$totalPages = ceil($totalResults / $options['limit']);

// Using this example, with 77 total results, would give you 4 pages
// If you want to go to page 3 of 4...
$page = 3;
$options['offset'] = ($page - 1) * $options['limit'];
$apiResults = GovSearch::search($search, $options);

/app/config/govsearch.php

/app/config/packages/iblank/laravel-gov-search/config.php