Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Lern Laravel Package

hmdev1/lern

LERN records Laravel exceptions to your database and sends notifications via Monolog channels like email, Slack, Pushover, SMS (Twilio/Plivo), Sentry, and more. Helps capture request/user context for faster debugging across Laravel versions.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation:

    composer require tylercd100/lern
    php artisan vendor:publish --provider="Tylercd100\LERN\LERNServiceProvider"
    php artisan migrate
    
  2. Configure app/Exceptions/Handler.php:

    use Tylercd100\LERN\Facades\LERN;
    
    public function report(Throwable $e)
    {
        if ($this->shouldReport($e) && app()->bound("lern")) {
            LERN::handle($e); // Records + Notifies
        }
        return parent::report($e);
    }
    
  3. First Use Case: Trigger an exception (e.g., abort(500)) and verify:

    • A record appears in vendor_tylercd100_lern_exceptions.
    • A notification arrives via your configured channel (e.g., Slack/Email).

Implementation Patterns

Core Workflows

  1. Exception Handling Pipeline:

    • Record Only: LERN::record($exception) → Stores data in DB.
    • Notify Only: LERN::notify($exception) → Sends alerts via Monolog.
    • Full Workflow: LERN::handle($exception) → Combines both.
  2. Dynamic Data Collection: Enable fields in config/lern.php:

    'collect' => [
        'method' => true,   // HTTP method (GET/POST/etc.)
        'data' => true,     // Request payload
        'user_id' => true,  // Authenticated user ID
        'url' => true,      // Request URL
    ]
    
  3. Notification Customization:

    • Blade Templates: Override resources/views/exceptions/default.blade.php.
    • Log Levels: Set globally in config or dynamically:
      LERN::setLogLevel('emergency'); // Overrides config
      

Integration Tips

  • User Context: Attach user data via middleware:
    LERN::setUser($user); // Sets $user for current request
    
  • Conditional Recording: Filter exceptions in Handler.php:
    if ($e instanceof \Symfony\Component\HttpKernel\Exception\HttpException && $e->getStatusCode() >= 500) {
        LERN::handle($e);
    }
    
  • Custom Handlers: Extend Monolog (e.g., Datadog, PagerDuty):
    LERN::pushHandler(new \Monolog\Handler\SyslogHandler('udp://logs.example.com'));
    

Gotchas and Tips

Pitfalls

  1. Migration Conflicts:

    • If vendor_tylercd100_lern_exceptions exists, reset it or rename the table in config/lern.php before migrating.
  2. Notification Delays:

    • Monolog handlers (e.g., Slack) may queue messages. Test with LERN::notify($e) directly to isolate issues.
  3. User Data Gaps:

    • user_id requires authentication. Use middleware to set it:
      LERN::setUser(auth()->user());
      
  4. Deprecated Methods:

    • Avoid LERN::setMessage() if using Blade templates (set 'view' => null in config).

Debugging

  • Check Records:
    $lastException = \Tylercd100\LERN\Models\ExceptionModel::latest()->first();
    dd($lastException->toArray());
    
  • Log Level Debugging: Set lern.notify.log_level to debug to capture all events during testing.

Extension Points

  1. Custom Models: Extend ExceptionModel to add fields (e.g., environment, device_info):

    class CustomExceptionModel extends \Tylercd100\LERN\Models\ExceptionModel {
        protected $fillable = ['environment', 'device'];
    }
    

    Update config/lern.php:

    'model' => App\Models\CustomExceptionModel::class,
    
  2. Handler Priorities: Use LERN::pushHandler() for runtime additions (e.g., staging-only alerts):

    if (app()->environment('staging')) {
        LERN::pushHandler(new \Monolog\Handler\SlackHandler(env('SLACK_TOKEN'), '#staging-alerts'));
    }
    
  3. Rate Limiting: Combine with Laravel’s throttle middleware to avoid notification spam:

    LERN::notify($e)->throttle(5); // Max 5 notifications/minute
    
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
terminal42/code-quality-tools
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky