Laravel Web Tinker

Laravel Web Tinker

Artisan's tinker command is a great way to tinker with your application in the terminal. Unfortunately running a few lines of code, making edits, and copy/pasting code can be bothersome. Wouldn't it be great to tinker in the browser?

Originally published at https://github.com

This package will add a route to your application where you can tinker to your heart's content.

In case light hurts your eyes, there's a dark mode too.

A word to the wise

This package can run arbritary code. Unless you know what you are doing, you should never install or use this in a production environment, or any environment where you handle real world data.

Installation

You can install the package via composer:

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

Next, you must publish the assets from this package by running this command.

php artisan web-tinker:install

Optionally, you can publish the config file of the package.

php artisan vendor:publish --provider="Spatie\WebTinker\WebTinkerServiceProvider" --tag="config"

This is the content that will be published to config/web-tinker.php

return [

/*
 * The web tinker page will be available on this path.
 */
'path' => '/tinker',

/*
 * Possible values are 'auto', 'light' and 'dark'.
 */
'theme' => 'auto',

/*
 * By default this package will only run in local development.
 * Do not change this, unless you know what your are doing.
 */
'enabled' => env('APP_ENV') === 'local',

/* * This class can modify the output returned by Tinker. You can replace this with * any class that implements \Spatie\WebTinker\OutputModifiers\OutputModifier. */ 'output_modifier' => \Spatie\WebTinker\OutputModifiers\PrefixDateTime::class,

/*
 * If you want to fine-tune PsySH configuration specify
 * configuration file name, relative to the root of your
 * application directory.
 */
'config_file' => env('PSYSH_CONFIG', null),

];

Usage

By default this package will only run in a local environment.

Visit /tinker in your local environment of your app to view the tinker page.

Authorization

Should you want to run this in another environment (we do not recommend this), there are two steps you must perform.

  • You must register a viewWebTinker ability. A good place to do this is in the AuthServiceProvider that ships with Laravel.
public function boot()
{
    $this->registerPolicies();

Gate::define('viewWebTinker', function ($user = null) {
    // return true if access to web tinker is allowed
});

}

  • You must set the enabled variable in the web-tinker config file to true.

Modifying the output

You can modify the output of tinker by specifying an output modifier in the output_modifier key of the web-tinker config file. An output modifier is any class that implements \Spatie\WebTinker\OutputModifiers\OutputModifier.

This is how that interface looks like.

namespace Spatie\WebTinker\OutputModifiers;

interface OutputModifier { public function modify(string $output = ''): string; }

The default install of this package will use the PrefixDataTime output modifier which prefixes the output from Tinker with the current date time.

Testing

composer test

Thanks for reading

If you liked this post, share it with all of your programming buddies!

Follow me on Facebook | Twitter

Further reading

PHP with Laravel for beginners - Become a Master in Laravel

Projects in Laravel: Learn Laravel Building 10 Projects

Laravel for RESTful: Build Your RESTful API with Laravel

Laravel 5.8 Tutorial for Beginners

Fullstack Web Development With Laravel and Vue.js

Laravel 5.8 Ajax CRUD tutorial using Datatable JS

Laravel 5.8 Tutorial from Scratch for Beginners

Build RESTful API In Laravel 5.8 Example

Login with Google in Laravel 5.8 App using Socialite Package

Laravel PHP Framework Tutorial - Full Course for Beginners (2019)

laravel php web-development

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

PHP Web Application Development Company

As a top **PHP Web Application Development Company in USA**[https://www.dataeximit.com/php-development-services/](https://www.dataeximit.com/php-development-services/ "https://www.dataeximit.com/php-development-services/"), we at Data EximIT have...

PHP Website Development

Skenix Infotech is a leading PHP Web Development Company that helps companies get results with industry best practices. Get affordable PHP Development Services.

Laravel Development Company

Skenix Infotech is a top Laravel Website Development Company with Expert Laravel Developers that provides robust Laravel Development Services at fair costs.

Hire Dedicated PHP Developer

Looking to hire affordable yet experienced PHP developers? **[Hire Dedicated PHP Developer](https://hourlydeveloper.io/hire-dedicated-php-developer/ "Hire Dedicated PHP Developer")**, who can convert your idea to reality, within the stipulated...

Hire PHP Developer

Looking to develop a PHP based website from scratch or revamp your existing website? **[HourlyDeveloper.io](https://hourlydeveloper.io/ "HourlyDeveloper.io")** has always been an industry leader for companies and business owners looking to hire...