> For the complete documentation index, see [llms.txt](https://docs.allstak.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.allstak.io/getting-started/quickstart.md).

# Laravel SDK

## Laravel SDK

Official Laravel SDK for AllStack error tracking and monitoring by Techsea. This package provides seamless integration for error tracking and monitoring in your Laravel applications.

### Installation

You can install the package via composer:

```bash
composer require techsea/allstack-laravel
```

### Configuration

1. Add the following variables to your `.env` file:

```env
ALLSTACK_API_KEY=your-api-key
ALLSTACK_ENVIRONMENT=production
```

2. The service provider will be automatically registered thanks to Laravel's package discovery.

### Usage

#### Capturing Exceptions

```php
try {
    // Your code here
} catch (\Throwable $e) {
    app(Techsea\AllStack\AllStackClient::class)->captureException($e);
}
```

## For Global Capturing Exceptions Laravel 11x

```php
return Application::configure(basePath: dirname(__DIR__))
    ->withRouting(
        web: __DIR__.'/../routes/web.php',
        commands: __DIR__.'/../routes/console.php',
        health: '/up',
    )
    ->withMiddleware(function (Middleware $middleware) {
        $middleware->append(\Techsea\AllStack\Middleware\AllStackMiddleware::class);
    })
    ->withExceptions(function (Exceptions $exceptions) {
        // Register a custom exception reporting callback
        $exceptions->report(function (Throwable $exception) {
            // Resolve the AllStackClient from the container
            $allStackClient = app(AllStackClient::class);
            
            // Capture the exception using AllStack
            $allStackClient->captureException($exception);
            
            // Optionally, stop further propagation to Laravel's default logging
            // return false; // Uncomment to prevent default logging
        });
    })
    ->create();
```

## For Laravel 8x

<pre class="language-php"><code class="lang-php">use Techsea\AllStack\AllStackClient;
<strong>php
</strong>class Handler extends ExceptionHandler
{
    /**
     * A list of the exception types that are not reported.
     *
     * @var array&#x3C;int, class-string&#x3C;Throwable>>
     */
    protected $dontReport = [
        //
    ];

    /**
     * A list of the inputs that are never flashed for validation exceptions.
     *
     * @var array&#x3C;int, string>
     */
    protected $dontFlash = [
        'current_password',
        'password',
        'password_confirmation',
    ];

    /**
     * Register the exception handling callbacks for the application.
     *
     * @return void
     */
    public function register()
    {
        $this->reportable(function (Throwable $e) {
            $allStackClient = app(AllStackClient::class);
            
            // Capture the exception using AllStack
            $allStackClient->captureException($e);
        });
    }
}
</code></pre>

#### Tracking HTTP Requests

Add the middleware to your `app/Http/Kernel.php`:

```php
protected $middleware = [
    // ...
    \Techsea\AllStack\Middleware\AllStackMiddleware::class,
];
```

Or use it in specific routes:

```php
Route::middleware([\Techsea\AllStack\Middleware\AllStackMiddleware::class])->group(function () {
    // Your routes here
});
```

### Features

* Exception tracking with stack traces
* HTTP request monitoring
* System information collection
* Environment-specific configuration
* Automatic context gathering
* Error handling and logging
