PHP code example of jan-drda / laravel-google-custom-search-engine

1. Go to this page and download the library: Download jan-drda/laravel-google-custom-search-engine 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/ */

    

jan-drda / laravel-google-custom-search-engine example snippets


'providers' => [
    '...',
    'JanDrda\LaravelGoogleCustomSearchEngine\LaravelGoogleCustomSearchEngineProvider'
];

'aliases' => [
	...
	'GoogleCseSearch' => 'JanDrda\LaravelGoogleCustomSearchEngine\Facades\LaravelGoogleCustomSearchEngineProvider',
	...
]

$fulltext = new LaravelGoogleCustomSearchEngine(); // initialize
$results = $fulltext->getResults('some phrase'); // get first 10 results for query 'some phrase' 

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;
use JanDrda\LaravelGoogleCustomSearchEngine\LaravelGoogleCustomSearchEngine;

class GoogleSearchController extends Controller
{

  public function index(){
    $fulltext = new LaravelGoogleCustomSearchEngine(); // initialize
    $results = $fulltext->getResults('some phrase'); // get first 10 results for query 'some phrase' 
  }
}

$fulltext = new LaravelGoogleCustomSearchEngine(); // initialize
$results = $fulltext->getResults('some phrase'); // get first 10 results for query 'some phrase' 
$info = $fulltext->getSearchInformation(); // get search information

$parameters = array(
    'start' => 10 // start from the 10th results,
    'num' => 10 // number of results to get, 10 is maximum and also default value
)

$fulltext = new LaravelGoogleCustomSearchEngine(); // initialize
$results = $fulltext->getResults('some phrase', $parameters); // get second 10 results for query 'some phrase'

$fulltext = new LaravelGoogleCustomSearchEngine(); // initialize
$results = $fulltext->getResults('some phrase'); // get first 10 results for query 'some phrase'
$rawResults = $fulltext->getRawResults(); // get complete response from Google

$fulltext = new LaravelGoogleCustomSearchEngine(); // initialize
$results =  $fulltext->getResults('some phrase'); // get first 10 results for query 'some phrase'
$noOfResults = $fulltext->getTotalNumberOfResults(); // get total number of results (it can be less than 10)

$fulltext = new LaravelGoogleCustomSearchEngine(); // initialize

$fulltext->setEngineId('someEngineId'); // sets the engine ID
$fulltext->setApiKey('someApiId'); // sets the API key

$results =  $fulltext->getResults('some phrase'); // get first 10 results for query 'some phrase'
bash
php artisan vendor:publish --provider="JanDrda\LaravelGoogleCustomSearchEngine\LaravelGoogleCustomSearchEngineProvider"