> ## Documentation Index
> Fetch the complete documentation index at: https://docs.westyx.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# PHP SDK - Laravel

> Auto-discovered service provider, container bindings, configuration file, Workload Identity Federation, and live updates in a worker.

Laravel discovers the service provider automatically, so installing the package is the whole setup.

## Setup

```sh theme={null}
composer require westyx/nexus
```

```env theme={null}
NEXUS_BASE_URL=https://blue-ocean-a5rx7.westyx.dev
NEXUS_API_KEY=wxs_...
```

That is all. The client is now resolvable anywhere:

```php theme={null}
use WestyxNexus\NexusClient;

final class BillingService
{
    public function __construct(private readonly NexusClient $nexus) {}

    public function endpoint(): string
    {
        return $this->nexus->getConfig('billing_endpoint', 'https://billing.example.com');
    }
}
```

Or through the container alias:

```php theme={null}
$host    = app('nexus')->getConfig('db_host');
$enabled = app('nexus')->getFlag('new-checkout', false);
```

## What comes from your container

Two things, so the SDK fits the application rather than the other way round:

* **The PSR-18 client.** Nexus traffic goes through the HTTP stack your application already configures - its proxy settings, middleware and instrumentation apply. If nothing is bound, the SDK discovers whatever implementation the project has. See [HTTP client](/sdks/php/http-client).
* **The PSR-3 logger.** SDK diagnostics land in your application log with nothing to configure. See [Custom logging](/sdks/php/custom-logging).

## Lazy by design

<Note>
  The binding is deferred and lazy. Creating a client performs a network round-trip, so nothing happens until something actually resolves `NexusClient` - registering the provider costs nothing, and an application that never reads a config never pays for one.
</Note>

Once resolved it is a singleton: the snapshot is shared for the rest of the request, or for the life of a worker.

## Configuration

The defaults apply whether or not you publish the file. Publish it to change anything beyond the environment variables:

```sh theme={null}
php artisan vendor:publish --tag=nexus-config
```

```php theme={null}
// config/nexus.php
return [
    'base_url' => env('NEXUS_BASE_URL', ''),
    'api_key'  => env('NEXUS_API_KEY', ''),
    'ttl'      => (int) env('NEXUS_TTL', 60),

    // Null uses the application's default channel.
    'log_channel' => env('NEXUS_LOG_CHANNEL'),

    // Live updates, for queue workers and console commands.
    'sse' => [
        'connect_timeout'    => (int) env('NEXUS_SSE_CONNECT_TIMEOUT', 10),
        'idle_timeout'       => (int) env('NEXUS_SSE_IDLE_TIMEOUT', 60),
        'reconnect_cooldown' => null,
    ],

    // Workload Identity Federation: no API key needed when enabled.
    'wif' => [
        'enabled'    => (bool) env('NEXUS_WIF_ENABLED', false),
        'provider'   => env('NEXUS_WIF_PROVIDER', 'auto'),
        'aws_region' => env('NEXUS_WIF_AWS_REGION', ''),
    ],
];
```

## A dedicated log channel

```env theme={null}
NEXUS_LOG_CHANNEL=nexus
```

```php theme={null}
// config/logging.php
'nexus' => [
    'driver' => 'single',
    'path'   => storage_path('logs/nexus.log'),
    'level'  => env('NEXUS_LOG_LEVEL', 'info'),
],
```

Secret values and secret key names never appear in that output - see [Custom logging](/sdks/php/custom-logging).

## Workload Identity Federation

On EKS, GKE, AKS or any Kubernetes cluster, drop the API key entirely:

```env theme={null}
NEXUS_BASE_URL=https://blue-ocean-a5rx7.westyx.dev
NEXUS_WIF_ENABLED=true
NEXUS_WIF_PROVIDER=auto
```

The workload's own identity is exchanged for a short-lived session, refreshed transparently before it expires. See [Workload identity](/sdks/php/workload-identity).

## Live updates in a worker

`connectStream()` blocks and does not return, so it belongs in a dedicated console command rather than in a request:

```php theme={null}
// app/Console/Commands/NexusWatch.php
namespace App\Console\Commands;

use Illuminate\Console\Command;
use WestyxNexus\NexusClient;

final class NexusWatch extends Command
{
    protected $signature = 'nexus:watch';
    protected $description = 'Follow the Nexus live-update stream';

    public function handle(NexusClient $nexus): void
    {
        $nexus->connectStream();
    }
}
```

Run it under your process supervisor alongside `queue:work`. See [SSE live updates](/sdks/php/sse-live-updates).

## Supported versions

Laravel **11, 12 and 13**. The package installs cleanly in a non-Laravel project too - the provider class is only loaded by Laravel's own discovery.
