PHP code example of gorilladash / laravel-website-sdk
1. Go to this page and download the library: Download gorilladash/laravel-website-sdk 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/ */
gorilladash / laravel-website-sdk example snippets
use GorillaDash\WebsiteSdk\Facades\GorillaDash;
use GraphQL\Query;
use GraphQL\RawObject;
use GraphQL\Variable;
// Pass a Query object — returns the GraphQL `data` array (SWR cached):
$query = (new Query('websiteInfo'))->setSelectionSet(['name', 'url']);
$data = GorillaDash::graphql($query);
// With variables — declare them on the query, pass values as the second arg:
$query = (new Query('websitePage'))
->setVariables([new Variable('slug', 'String', true)])
->setArguments(['slug' => new RawObject('$slug')])
->setSelectionSet(['name', 'body']);
$data = GorillaDash::graphql($query, ['slug' => 'about-us']);
// graphqlWithMeta() also accepts a raw query string, and returns the full cache
// envelope (status: miss | fresh | stale, age in seconds):
$result = GorillaDash::graphqlWithMeta('{ websiteInfo { name } }');
// => ['data' => [...], 'cached_at' => 1718..., 'age' => 0, 'status' => 'miss']
// Per-call overrides (different credentials, or a custom TTL):
$data = GorillaDash::connection(['cache_ttl' => 300])->graphql($query);
// Verify credentials (throws GdRequestException on failure):
GorillaDash::ping();
use GorillaDash\WebsiteSdk\Exceptions\GdRequestException;
use GraphQL\Query;
try {
$info = GorillaDash::graphql((new Query('websiteInfo'))->setSelectionSet(['name', 'url']));
} catch (GdRequestException $e) {
$info = null; // render a fallback; $e->graphqlErrors holds GraphQL error details
}
use GraphQL\Query;
return Inertia::render('Home', [
'info' => GorillaDash::graphql(
(new Query('websiteInfo'))->setSelectionSet(['name', 'url'])
),
'menu' => GorillaDash::graphql(
(new Query('websiteMenu'))
->setArguments(['name' => 'Main Menu'])
->setSelectionSet(['name', 'menu_json'])
),
]);