PHP code example of illuma-law / laravel-places-scout

1. Go to this page and download the library: Download illuma-law/laravel-places-scout 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/ */

    

illuma-law / laravel-places-scout example snippets


return [
    /**
     * Your Google Places API Key.
     * Obtain an API key from the Google Cloud Console:
     * https://console.cloud.google.com/google/maps-apis/credentials
     */
    'api_key' => env('GOOGLE_PLACES_API_KEY'),
];

use IllumaLaw\PlacesScout\Facades\PlacesScout;

// Basic text search
$response = PlacesScout::textSearch('Law firms in New York');

if ($response) {
    foreach ($response->results as $result) {
        echo $result->name;             // 'Smith & Associates'
        echo $result->placeId;          // 'ChIJ...'
        echo $result->formattedAddress; // '123 Main St, New York, NY'
        echo $result->latitude;         // 40.7128
        echo $result->longitude;        // -74.0060
        echo $result->rating;           // 4.8
    }

    // Handle pagination using the nextPageToken
    if ($response->nextPageToken) {
        $nextPage = PlacesScout::textSearch('Law firms in New York', $response->nextPageToken);
    }
}

use IllumaLaw\PlacesScout\Facades\PlacesScout;

$details = PlacesScout::getPlaceDetails('ChIJN1t_tDeuEmsRUsoyG83frY4');

if ($details) {
    echo $details->name;              // 'Google Australia'
    echo $details->phoneNumber;       // '(02) 9374 4000'
    echo $details->website;           // 'https://www.google.com.au/'
    echo $details->formattedAddress;  // '48 Pirrama Rd, Pyrmont NSW 2009, Australia'
    echo $details->rating;            // 4.4
    echo $details->userRatingsTotal;  // 123
    echo $details->latitude;          // -33.866651
    echo $details->longitude;         // 151.195827
}

use IllumaLaw\PlacesScout\Facades\PlacesScout;

$userApiKey = $user->settings->google_api_key;

// Override API key for this specific request
$response = PlacesScout::withApiKey($userApiKey)->textSearch('Restaurants in Paris');

namespace App\Http\Controllers;

use IllumaLaw\PlacesScout\PlacesScoutService;

class LocationController extends Controller
{
    public function __construct(
        private PlacesScoutService $placesScout
    ) {}

    public function search(string $query)
    {
        $results = $this->placesScout->textSearch($query);

        return response()->json($results);
    }
}