laravel-google-custom-search-engine icon indicating copy to clipboard operation
laravel-google-custom-search-engine copied to clipboard

How to use in Laravel 5.1 ?

Open avesgit opened this issue 8 years ago • 4 comments
trafficstars

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

avesgit avatar Dec 15 '16 19:12 avesgit

Sorry for being late.

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

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

  3. 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?

jdrda avatar Dec 22 '16 11:12 jdrda

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); 
  }
 
}

Mirza-Obaid avatar Feb 16 '17 07:02 Mirza-Obaid

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

febridev avatar May 01 '17 04:05 febridev

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>

Dinesh-Wasnik avatar Mar 19 '19 02:03 Dinesh-Wasnik