Laravel’s Tinker is an incredibly powerful REPL (Read-Eval-Print Loop) that lets you interact with your Laravel application from the command line. It’s perfect for quickly testing out code and inspecting your application. However, typing multi-line code in the terminal can sometimes feel a bit clunky.
What if you could access Tinker directly within Chrome DevTools?
Yes, you read that right! Thanks to a Chrome extension by Tony Lea, you can now run Laravel Tinker directly in the browser, integrated within the Chrome DevTools interface.
This extension utilizes Spatie's Laravel Web Tinker package and embeds the /tinker
route (which is created by the package in your Laravel project) directly into DevTools via an iframe. This means you can run your Laravel Tinker commands without leaving the browser.
By integrating Laravel Tinker in DevTools, your workflow becomes more seamless, making it easier to test and debug without constantly switching between terminal and browser tabs.
How to Set It Up
1. Install the Laravel Web Tinker Package
Before using the Chrome extension, you need to have the Laravel Web Tinker package installed in your Laravel project. To do this, run the following command in your terminal:
composer require spatie/laravel-web-tinker --dev
2. Publish the Assets
Once the package is installed, you'll need to publish its assets. To do this, run:
php artisan vendor:publish --provider="Spatie\LaravelWebTinker\WebTinkerServiceProvider"
3. Install the Chrome Extension
With the backend setup complete, you can install the Chrome extension. The extension is available for manual installation. For installation instructions, visit the GitHub repository.
Once installed, you'll see a new PHP tab appear in Chrome DevTools. This is where you’ll run your Tinker commands directly in your browser.
The Workflow
Whenever you’re working with Laravel, simply open Chrome DevTools, click on the PHP tab, and start using Tinker right within your browser window.
No need to switch between different applications or tabs—everything you need is in one place!
Why Use This Setup?
Here’s why you should consider integrating Laravel Tinker into Chrome DevTools:
- Faster Development: Say goodbye to switching between the terminal and browser. Keep everything in one place for faster iteration.
- Test Directly in the Browser: Run and test your Laravel code without needing to open a separate terminal window.
- Efficient Workflow: Stay within the browser and streamline your development process.
Additional Features of Laravel Web Tinker
In addition to Tinker, the Laravel Web Tinker package offers other helpful features for interacting with your Laravel application directly from the browser. These features allow you to quickly test, debug, and inspect your application, all without leaving your development environment.