PHP code example of sluice / laravel-sluice

1. Go to this page and download the library: Download sluice/laravel-sluice library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

sluice / laravel-sluice example snippets


// In AuthServiceProvider (Laravel 10) or AppServiceProvider (Laravel 11+)
use Illuminate\Support\Facades\Gate;

Gate::define('view-sluice', function ($user) {
    return $user->hasRole('developer');  // Your logic here
});

// In config/sluice.php
'auth_gate' => null,
'auth_callback' => fn($user) => in_array($user->email, ['[email protected]']),

// In config/sluice.php
'auth_gate' => null,
'auth_env' => 'SLUICE_ACCESS',

// In config/sluice.php
'auth_gate' => null,
'auth_callback' => null,
'auth_env' => null,

'sources' => [
    'laravel' => [
        'type'    => 'file',
        'label'   => 'Laravel Log',
        'icon'    => 'bi-file-earmark-code',
        'badge'   => 'bg-danger',
        'enabled' => true,
        'paths'   => ['laravel.log'],
        'format'  => 'laravel',
    ],
],

'activity' => [
    'type'             => 'database',
    'label'            => 'Activity Logs',
    'icon'             => 'bi-database',
    'badge'            => 'bg-primary',
    'enabled'          => true,
    'table'            => 'activity_logs',
    'timestamp_column' => 'created_at',
    'mapping'          => [
        'level'   => 'log_level',
        'title'   => 'event_type',
        'message' => 'message',
        'context' => 'context',
        'user_id' => 'user_id',
    ],
    'filters' => [
        'search_columns' => ['event_type', 'message'],
        'level_column'   => 'log_level',
    ],
],

// In config/sluice.php
'capture_exceptions' => true,

use Sluice\LaravelSluice\Facades\Sluice;

Sluice::info('user_login', 'User logged in successfully', ['ip' => '1.2.3.4'], $userId);
Sluice::warning('rate_limit', 'API rate limit approaching', ['current' => 95, 'max' => 100]);
Sluice::error('payment_failed', 'Stripe charge declined', ['charge_id' => 'ch_xxx'], $userId);
Sluice::critical('database_down', 'Primary database connection lost');
Sluice::security('brute_force', 'Multiple failed login attempts', ['attempts' => 15], $userId);

use Sluice\LaravelSluice\Logging\TimelineLogger;

class PaymentController extends Controller
{
    public function __construct(
        protected TimelineLogger $logger
    ) {}

    public function charge(Request $request)
    {
        $this->logger->info('payment_initiated', 'Processing payment', [
            'amount' => $request->amount,
        ], auth()->id());
    }
}

Sluice::frontendError(
    message: 'TypeError: Cannot read property "x" of undefined',
    type: 'javascript',
    stack: $stackTrace,
    source: 'https://app.example.com/js/app.js',
    line: 42,
    column: 15,
    url: 'https://app.example.com/dashboard',
    context: ['browser' => 'Chrome 120'],
    userId: auth()->id()
);

Sluice::batch([
    ['event_type' => 'page_view', 'message' => '/dashboard', 'log_level' => 'info'],
    ['event_type' => 'page_view', 'message' => '/settings', 'log_level' => 'info'],
], $userId);

$schedule->command('sluice:clear --days=90 --force')->monthly();

// config/sluice.php
'api' => [
    'enabled'    => true,
    'prefix'     => 'api/sluice',
    'middleware' => ['api', 'auth:sanctum'],
],

[
    'source'       => 'source_key',
    'level'        => 'error',                // debug|info|warning|error|critical|security
    'timestamp'    => Carbon::instance(),
    'icon'         => 'bi-file-text',
    'badge_class'  => 'bg-danger',
    'source_badge' => 'bg-primary',
    'title'        => 'Source: ERROR',
    'subtitle'     => 'First 200 chars...',
    'details'      => ['key' => 'value'],
    'user_id'      => 42,                     // nullable
    'group_count'  => 1,
    'group_key'    => 'md5_hash',
]

Gate::define('view-sluice', fn($user) => $user->hasRole('developer'));

Gate::define('view-sluice', fn($user) => $user->hasRole('admin'));

use Sluice\LaravelSluice\Facades\Sluice;

Sluice::info('order_placed', 'Order #1234 placed', ['total' => 99.99], $user->id);
bash
php artisan vendor:publish --tag=sluice-config
bash
php artisan vendor:publish --tag=sluice-migrations
php artisan migrate
bash
php artisan vendor:publish --tag=sluice-views

sluice/laravel-sluice
+-- config/
|   +-- sluice.php                       -- All configuration
+-- database/migrations/
|   +-- create_sluice_tables.php         -- Optional DB tables
+-- resources/views/
|   +-- timeline.blade.php               -- Main page
|   +-- _sidebar.blade.php               -- Filter sidebar
|   +-- _timeline_content.blade.php      -- Timeline events
+-- routes/
|   +-- web.php                          -- Web dashboard routes
|   +-- api.php                          -- JSON API routes
+-- src/
    +-- SluiceServiceProvider.php
    +-- Console/Commands/                -- sluice:show, :stats, :export, :log, :clear
    +-- Facades/Sluice.php               -- Facade
    +-- Http/Controllers/
    |   +-- SluiceController.php         -- Web dashboard
    |   +-- Api/SluiceApiController.php  -- JSON API
    +-- Http/Middleware/SluiceAccess.php  -- Auth (4 strategies)
    +-- Listeners/ExceptionListener.php  -- Optional exception capture
    +-- Logging/TimelineLogger.php       -- Dual-driver logger
    +-- Models/                          -- Eloquent models
    +-- Sources/                         -- CloudWatch, S3, HTTP drivers
    +-- Services/TimelineService.php     -- Core aggregation engine
bash
composer vendor:publish --tag=sluice-config
php artisan vendor:publish --tag=sluice-migrations
php artisan migrate