Back to Blog
Tutorials 1 min read 21 views

Getting Started with StackWatch for Laravel

ST
StackWatch Team

Product Team

This guide will walk you through setting up StackWatch in your Laravel application. The entire process takes less than 5 minutes.

Prerequisites

  • Laravel 9.x or higher
  • PHP 8.1 or higher
  • A StackWatch account and project DSN

Step 1: Install the Package

Install the StackWatch Laravel package via Composer:

composer require stackwatch/stackwatch-laravel

Step 2: Publish Configuration

Publish the configuration file:

php artisan vendor:publish --tag=stackwatch-config

Step 3: Configure Your DSN

Add your StackWatch DSN to your .env file:

STACKWATCH_DSN=https://your-key@app.stackwatch.dev/your-project-id

Step 4: Test the Integration

Run the test command to verify everything is working:

php artisan stackwatch:test

You should see a test event appear in your StackWatch dashboard within seconds.

Additional Configuration

Custom Context

Add custom context to your error reports:

StackWatch::setUser([
    'id' => auth()->id(),
    'email' => auth()->user()->email,
]);

StackWatch::setContext('order', [
    'id' => $order->id,
    'total' => $order->total,
]);

Performance Monitoring

Enable performance monitoring in your configuration:

'performance' => [
    'enabled' => true,
    'sample_rate' => 0.5, // 50% of requests
],

That's it! StackWatch will now capture errors, exceptions, and performance data from your Laravel application.

Share this article

Related Posts