I'm currently organising Full Stack Europe. It's a conference in Antwerp, Belgium for developers who want to learn across the stack. You can use this link get your ticket with a nice discount.

A package to use Artisan Tinker in your browser

Original – by Freek Van der Herten – 2 minute read

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!

Stay up to date with all things Laravel, PHP, and JavaScript.

Every two weeks I send out a newsletter containing lots of interesting stuff for the modern PHP developer.

Expect quick tips & tricks, interesting tutorials, opinions and packages. Because I work with Laravel every day there is an emphasis on that framework.

Rest assured that I will only use your email address to send you the newsletter and will not use it for any other purposes.