Installation
composer require stentle-hackers/laravel-webcore
Ensure your Laravel version is 5.3+ (compatibility is strict).
Publish Config
php artisan vendor:publish --provider="Stentle\WebCore\WebCoreServiceProvider"
This generates a .env file with STENTLE_API_KEY and STENTLE_API_URL placeholders.
Configure these in your .env:
STENTLE_API_KEY=your_api_key_here
STENTLE_API_URL=https://api.stentle.com/v1
First API Call
Use the Stentle facade to interact with the API:
use Stentle\Facades\Stentle;
// Example: Fetch a product
$product = Stentle::product()->find(123);
Key Classes
Stentle::product() → Product API methods.Stentle::cart() → Cart operations.Stentle::order() → Order management.Stentle::customer() → Customer data.Product Management
$products = Stentle::product()->all(['limit' => 10]);
$product = Stentle::product()->create([
'name' => 'Laptop',
'price' => 999.99,
'sku' => 'LP-1000'
]);
Cart Operations
Stentle::cart()->add(123, 2); // Product ID, quantity
$order = Stentle::cart()->checkout(['customer_id' => 456]);
Order Processing
$orders = Stentle::order()->all(['status' => 'completed']);
Stentle::order()->update(789, ['status' => 'shipped']);
Customer Data
$customer = Stentle::customer()->find(456);
Stentle::customer()->update(456, ['email' => 'new@example.com']);
Laravel Eloquent Sync Use the package alongside Eloquent for hybrid data management:
// Sync Stentle products with local DB
$stentleProducts = Stentle::product()->all();
Product::upsert($stentleProducts, ['sku'], ['name', 'price']);
API Rate Limiting
The package handles retries for failed requests (configurable in config/webcore.php):
'retry_limit' => 3,
'retry_delay' => 100, // ms
Webhooks
Stentle supports webhooks for real-time updates (e.g., order status changes). Configure in config/webcore.php:
'webhook_secret' => 'your_webhook_secret',
'webhook_url' => route('stentle.webhook'),
Then create a route/controller to handle incoming payloads:
Route::post('/stentle/webhook', 'StentleWebhookController@handle');
Deprecated Laravel Version
API Key Leaks
.env file is not auto-generated by the vendor:publish command. Ensure STENTLE_API_KEY is never committed to version control..env.example templates.Rate Limits
429 Too Many Requests.Webhook Verification
Stentle-Signature header for validation. The package does not include this by default.$payload = file_get_contents('php://input');
$signature = $_SERVER['HTTP_STENTLE_SIGNATURE'];
$secret = config('webcore.webhook_secret');
if (!hash_equals($signature, hash_hmac('sha256', $payload, $secret))) {
abort(401, 'Invalid signature');
}
Enable API Logging
Add this to config/webcore.php to log all API requests/responses:
'debug' => true,
'log_file' => storage_path('logs/stentle.log'),
Common Errors
| Error | Cause | Solution |
|---|---|---|
ClientException |
Invalid API key or endpoint | Verify .env and Stentle dashboard |
ConnectionException |
API URL misconfigured | Check STENTLE_API_URL |
ValidationException |
Missing/invalid payload fields | Review Stentle API docs for required fields |
RateLimitExceededException |
Too many requests | Implement backoff or upgrade plan |
Custom API Endpoints The package uses Guzzle under the hood. Extend it by creating a custom service:
use Stentle\WebCore\Client;
class CustomStentleClient extends Client
{
public function customEndpoint($method, $endpoint, $data = [])
{
return $this->request($method, $endpoint, $data);
}
}
Register it in AppServiceProvider:
$this->app->singleton('stentle.custom', function () {
return new CustomStentleClient(config('webcore'));
});
Middleware for API Calls Add middleware to modify requests/responses globally. Example:
// In AppServiceProvider
$this->app['stentle']->getClient()->getEmitter()->attach(
new class extends Middleware {
public function handle($request, Closure $next)
{
// Add custom headers
$request->setHeader('X-Custom-Header', 'value');
return $next($request);
}
}
);
Testing Mock the Stentle client in tests:
$mock = Mockery::mock('overload:Stentle\WebCore\Client');
$mock->shouldReceive('request')->andReturn(['data' => 'mocked']);
How can I help you explore Laravel packages today?