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.
Installation:
composer require spatie/laravel-web-tinker --dev
php artisan web-tinker:install
This publishes the frontend assets and config file.
First Use:
Visit /tinker in your local Laravel environment (default path). No authentication is required in local by default.
Quick Test: Run a simple Laravel command like:
User::first()
or test Eloquent queries:
DB::table('users')->count()
config/web-tinker.php (path, theme, middleware, output modifiers)public/vendor/web-tinker (Vue.js frontend)Debugging Models/Queries:
// Test a relationship
$user = User::find(1);
$user->posts()->count();
// Chain queries
User::where('active', true)->get()->pluck('email');
Testing API Responses:
$response = Http::get('https://api.example.com/users');
$response->json();
Interactive Testing:
// Test a method incrementally
$user = User::find(1);
$user->update(['name' => 'New Name']);
$user->fresh()->name; // Verify change
Custom Output Modifiers:
Extend \Spatie\WebTinker\OutputModifiers\OutputModifier to format output:
// config/web-tinker.php
'output_modifier' => App\OutputModifiers\CustomModifier::class,
middleware array in config to restrict access (e.g., auth).config_file in config:
'config_file' => '.psyshrc.php',
theme config ('auto', 'light', or 'dark').Testing Jobs/Queues:
dispatch(new SendEmailJob($user));
// Check queue
Bus::dispatchNow(new SendEmailJob($user));
Mocking Dependencies:
$mock = Mockery::mock('App\Services\PaymentService');
$mock->shouldReceive('charge')->once()->andReturn(true);
app()->instance('App\Services\PaymentService', $mock);
Real-Time Feedback:
Use dd() or dump() for quick inspection:
dump($user->posts->toArray());
Security:
Gate::define('viewWebTinker', ...)..env to disable in non-local environments:
APP_ENV=production
Docker/Hanging Requests:
PSYSH_CONFIG is set if using custom configs.while(true)).Output Formatting:
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);
}
}
PsySH Quirks:
readline() calls (not supported in web context).exit or return to terminate execution cleanly.Empty Output:
storage/logs/laravel.log).PSYSH_CONFIG is readable if custom config is used.Slow Responses:
memory_get_usage().Middleware Conflicts:
'middleware' => [\Illuminate\Session\Middleware\StartSession::class],
Custom Commands:
Add aliases to .psyshrc.php:
Psy\Configuration::getAliasManager()->define('u', 'User::first()');
UI Customization:
Override the Vue.js frontend in resources/js/web-tinker (published assets).
Event Listeners:
Hook into WebTinkerExecuting events (if available in future versions) to log usage.
/tinker for quick access during development.!! to force evaluation (e.g., !!User::count()).php artisan cache:clear if output modifiers stop working.How can I help you explore Laravel packages today?