# 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


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.allstak.io/getting-started/quickstart.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
