1. Go to this page and download the library: Download tonylabs/laravel-digikey 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/ */
tonylabs / laravel-digikey example snippets
use TONYLABS\DigiKey\DigiKey;
use TONYLABS\DigiKey\Product\SortField;
use TONYLABS\DigiKey\Product\SortOrder;
$digikey = (new DigiKey())
->setCategoryFilter(872)
->setManufacturerFilter(1904)
->setLocaleLanguage('en')
->setLocaleCurrency('USD')
->setLocaleSite('US')
->setLimit(50)
->setOffset(100)
->setOrder(SortField::QuantityAvailable, SortOrder::Descending);
$results = $digikey->searchKeyword('DCP0606QTRY');
// Per-call overrides still work as before
$results = $digikey->searchKeyword('DCP0606QTRY', [
'limit' => 25,
'offset' => 0,
]);
// Pure category/manufacturer browse (no keywords)
$results = (new DigiKey())
->setCategoryFilter(872)
->setManufacturerFilter(1904)
->setOrder(SortField::Price, SortOrder::Ascending)
->searchKeyword(null, [
'limit' => 25,
]);
$digikey = new DigiKey(client_id: 'your_client_id', client_secret: 'your_client_secret');
use TONYLABS\DigiKey\Product\KeywordSearchRequest;
$request = (new KeywordSearchRequest('resistor'))
->setMinimumQuantityAvailable(100);
$results = (new DigiKey())->searchKeyword($request);
use TONYLABS\DigiKey\Facades\DigiKey;
// Search for products without constructing a request object
$results = DigiKey::searchKeyword('resistor');
// Optionally provide overrides using the same helper keys as DigiKey::searchKeyword
$stockedChips = DigiKey::searchKeyword('stm32', [
'limit' => 50,
'filters' => [
'FilterOptionsRequest' => [
'MinimumQuantityAvailable' => 25,
],
],
]);
// Get product details
$productDetails = DigiKey::getProductDetails('296-1173-1-ND');
// Get manufacturers
$manufacturers = DigiKey::getManufacturers();
// Access the lower-level array API if needed
// $raw = DigiKey::getHttpClient();
use TONYLABS\DigiKey\Services\DigiKeyOAuthService;
// Get access token (automatically cached)
$oauth = app(DigiKeyOAuthService::class);
$accessToken = $oauth->getAccessToken();
// Check if we have a valid cached token
$hasValidToken = $oauth->hasValidToken();
// Clear cached token if needed
$oauth->clearCachedToken();