DEV Community

Freek Van der Herten
Freek Van der Herten

Posted on • Originally published at on

★ A package to use Artisan Tinker in your browser

Laravel comes with a very handy tinker command out of the box. Unfortunately running multiple lines of code on the command line, or editing the code you just executed, can be a bit bothersome. That's why we created a new package called laravel-web-tinker that allows you to run arbitrary code in your browser.

Once installed this is what it looks like:

Web tinker in the browser

There's also a dark mode available:

Web tinker in dark mode on the brower

Under the hood, it works like this. Whenever you press cmd+enter the code will be sent via an HTTP request to the server. The WebTinkerContoller will just pass the code through the Tinker class. The code will be executed there and the results will be returned as the response. Nothing special going there.

Because this package can run code arbitrarily we recommend against installing it in a production environment, or any environment where you handle real-world data. We urge you to install the package using the --dev flag

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

This means that the package will not be installed when you run composer install --no-dev on your production server (this is something you should be doing already).

There are some more config options. Check out the readme on GitHub to learn more about the package.

Happy tinkering!

Top comments (0)