Get "PHP 8 in a Nuthshell" (Now with PHP 8.4)
Amit Merchant

Amit Merchant

A blog on PHP, JavaScript, and more

Using Laravel Tinker in Chrome DevTools

Laravel’s Tinker package is a powerful REPL (Read-Eval-Print Loop) tool that allows you to interact with your Laravel application from the command line. It’s a great tool to test your application’s code without having to go through the hassle of creating a new controller or a route.

Once installed, you can essentially run the Laravel-specific code just by invoking the php artisan tinker command in your terminal. However, writing code in the terminal can sometimes be cumbersome, especially when dealing with multiple-line code.

But what if I tell you you can use Laravel Tinker even in Chrome DevTools?

Yes, you heard it right! We now have a Chrome extension by Tony Lea which, once installed, will add a new tab in Chrome DevTools called “PHP”.

The trick that this extension pulls off is it utilizes Spatie’s Laravel Web Tinker package, and iframes the route /tinker (created by the package for the project) in the devtools panel, making it accessible throughout the development process without switching tabs.

Here’s what that looks like.

Laravel Tinker in Chrome DevTools

The only prerequisite to using this extension is that you need to have the Laravel Web Tinker package installed in your Laravel application beforehand. You can install the package as a dev dependency using the following command.

composer require spatie/laravel-web-tinker --dev

Then publish the assets and you’re good to go.

Currently, you can install the extension manually the instructions of which can be found on its GitHub repository.

Learn the fundamentals of PHP 8 (including 8.1, 8.2, 8.3, and 8.4), the latest version of PHP, and how to use it today with my new book PHP 8 in a Nutshell. It's a no-fluff and easy-to-digest guide to the latest features and nitty-gritty details of PHP 8. So, if you're looking for a quick and easy way to PHP 8, this is the book for you.

Like this article?

Buy me a coffee

👋 Hi there! I'm Amit. I write articles about all things web development. You can become a sponsor on my blog to help me continue my writing journey and get your brand in front of thousands of eyes.

Comments?