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

Laravel Web Tinker Laravel Package

spatie/laravel-web-tinker

Adds Laravel’s Tinker REPL to your browser via a protected route, making it easy to run and tweak code without the terminal. Includes light/dark UI and simple install/publish commands. For local/dev only—can execute arbitrary code.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation:

    composer require spatie/laravel-web-tinker --dev
    php artisan web-tinker:install
    

    This publishes the frontend assets and config file.

  2. First Use: Visit /tinker in your local Laravel environment (default path). No authentication is required in local by default.

  3. Quick Test: Run a simple Laravel command like:

    User::first()
    

    or test Eloquent queries:

    DB::table('users')->count()
    

Key Files to Review

  • Config: config/web-tinker.php (path, theme, middleware, output modifiers)
  • Assets: Published to public/vendor/web-tinker (Vue.js frontend)

Implementation Patterns

Daily Workflow

  1. Debugging Models/Queries:

    // Test a relationship
    $user = User::find(1);
    $user->posts()->count();
    
    // Chain queries
    User::where('active', true)->get()->pluck('email');
    
  2. Testing API Responses:

    $response = Http::get('https://api.example.com/users');
    $response->json();
    
  3. Interactive Testing:

    // Test a method incrementally
    $user = User::find(1);
    $user->update(['name' => 'New Name']);
    $user->fresh()->name; // Verify change
    
  4. Custom Output Modifiers: Extend \Spatie\WebTinker\OutputModifiers\OutputModifier to format output:

    // config/web-tinker.php
    'output_modifier' => App\OutputModifiers\CustomModifier::class,
    

Integration Tips

  • Middleware: Add custom middleware to the middleware array in config to restrict access (e.g., auth).
  • PsySH Config: Override default PsySH behavior via config_file in config:
    'config_file' => '.psyshrc.php',
    
  • Dark/Light Theme: Toggle via theme config ('auto', 'light', or 'dark').

Advanced Use Cases

  1. Testing Jobs/Queues:

    dispatch(new SendEmailJob($user));
    // Check queue
    Bus::dispatchNow(new SendEmailJob($user));
    
  2. Mocking Dependencies:

    $mock = Mockery::mock('App\Services\PaymentService');
    $mock->shouldReceive('charge')->once()->andReturn(true);
    app()->instance('App\Services\PaymentService', $mock);
    
  3. Real-Time Feedback: Use dd() or dump() for quick inspection:

    dump($user->posts->toArray());
    

Gotchas and Tips

Common Pitfalls

  1. Security:

    • Never use in production (arbitrary code execution risk).
    • Restrict access via middleware or Gate::define('viewWebTinker', ...).
    • Use .env to disable in non-local environments:
      APP_ENV=production
      
  2. Docker/Hanging Requests:

    • Ensure PSYSH_CONFIG is set if using custom configs.
    • Avoid long-running loops (e.g., while(true)).
  3. Output Formatting:

    • Default output includes timestamps. Override with a custom OutputModifier:
      class NoTimestampModifier implements OutputModifier {
          public function modify(string $output): string {
              return preg_replace('/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\s/', '', $output);
          }
      }
      
  4. PsySH Quirks:

    • Avoid readline() calls (not supported in web context).
    • Use exit or return to terminate execution cleanly.

Debugging Tips

  1. Empty Output:

    • Check for PHP errors in Laravel logs (storage/logs/laravel.log).
    • Verify PSYSH_CONFIG is readable if custom config is used.
  2. Slow Responses:

    • Disable output modifiers temporarily to isolate the issue.
    • Monitor memory usage with memory_get_usage().
  3. Middleware Conflicts:

    • Temporarily remove custom middleware to test:
      'middleware' => [\Illuminate\Session\Middleware\StartSession::class],
      

Extension Points

  1. Custom Commands: Add aliases to .psyshrc.php:

    Psy\Configuration::getAliasManager()->define('u', 'User::first()');
    
  2. UI Customization: Override the Vue.js frontend in resources/js/web-tinker (published assets).

  3. Event Listeners: Hook into WebTinkerExecuting events (if available in future versions) to log usage.

Pro Tips

  • Bookmark /tinker for quick access during development.
  • Use !! to force evaluation (e.g., !!User::count()).
  • Clear Cache: Run php artisan cache:clear if output modifiers stop working.
  • Test Locally First: Always validate changes in a local environment before sharing.
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.
codraw/framework-extra-bundle
codraw/messenger
codraw/security
codraw/mailer
codraw/contracts
codraw/profiling
codraw/dependency-injection
codraw/tester
codraw/core
nexmo/api-specification
capell-app/block-library
axium/identity
cetria/laravel-dummy-models
cetria/reflection-helper
agropredict/sso-auth-bundle
evolvestudio/spam-protection
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony