jdrda / laravel-google-custom-search-engine

Laravel package to get Google Custom Search results from Google Custom Search Engine API for both free and paid versions.
MIT License
48 stars 17 forks source link

How to use in Laravel 5.1 ? #1

Open avesgit opened 7 years ago

avesgit commented 7 years ago

I try use in laravel 5.1

Use provider JanDrda\LaravelGoogleCustomSearchEngine\LaravelGoogleCustomSearchEngineProvider::class, alias 'GoogleCseSearch' => JanDrda\LaravelGoogleCustomSearchEngine\Facades\LaravelGoogleCustomSearchEngineProvider::class,

but then i dont know what to do

jdrda commented 7 years ago

Sorry for being late.

  1. Publish the config from command line

    php artisan vendor:publish --provider="JanDrda\LaravelGoogleCustomSearchEngine\LaravelGoogleCustomSearchEngineProvider"
  2. Get all configuration values as described in README and save it https://github.com/jdrda/laravel-google-custom-search-engine#configuration

  3. In your controller map the namespace with use: use JanDrda\LaravelGoogleCustomSearchEngine\LaravelGoogleCustomSearchEngine;

  4. Use in you controller like described in README https://github.com/jdrda/laravel-google-custom-search-engine#usage

So example controller will be:

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' 
  }
}

Is it clear?

Mirza-Obaid commented 7 years ago

i am getting an empty array in result in laravel 5.2

<?php
namespace App\Http\Controllers;

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

class SearchController extends Controller
{

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

}
febridev commented 7 years ago

i have same problem, empty array in results in laravel 5.4 @jdrda
could you please give example with view ?

Dinesh-Wasnik commented 5 years ago

I have also same problem getting result 0 here is object.

{#584 ▼
  +"searchTime": 0.175679
  +"formattedSearchTime": "0.18"
  +"totalResults": "0"
  +"formattedTotalResults": "0"
}

How to fix this .

With this js code , i am getting result

      (function() {
        var cx = '017660551690868778841:usjd0spoeoe';
        var gcse = document.createElement('script');
        gcse.type = 'text/javascript';
        gcse.async = true;
        gcse.src = 'https://cse.google.com/cse.js?cx=' + cx;
        var s = document.getElementsByTagName('script')[0];
        s.parentNode.insertBefore(gcse, s);
      })();
</script>
<gcse:search></gcse:search>