luminarix/laravel-web-tinker

Small Laravel package to use Tinker in your browser

Fund package maintenance!
luminarix

Installs: 440

Dependents: 0

Suggesters: 0

Security: 0

Stars: 2

Watchers: 1

Forks: 0

Open Issues: 0

Language:TypeScript

v0.1.5 2024-05-26 19:39 UTC

This package is auto-updated.

Last update: 2024-06-01 21:27:50 UTC


README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

This package allows you to use Tinker in your browser. Wildly inspired by Spatie's Laravel Web Tinker, but with added functionality, and React frontend.

🚨 A word to the wise 🚨

This package can run arbitrary 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.

Known issues

  • None. Please report any issues you find.

Requirements

  • PHP ^8.3
  • Laravel ^11.0

Extra features

  • Tabs for multiple code snippets
    • Tabs can be renamed
    • Tabs have their own code history
    • Both of the above are saved in local storage, so they persist between sessions and page reloads
  • Runtime counter displayed while loading and total runtime displayed in the final output
  • Loading state is displayed while the code is running

Installation

If you've used Spatie's Laravel Web Tinker before, please remove the config/web-tinker.php file before installing this package.

You can install the package via composer:

composer require luminarix/laravel-web-tinker

Publish the assets:

php artisan vendor:publish --tag="laravel-web-tinker-assets"

You can publish the config file with:

php artisan vendor:publish --tag="laravel-web-tinker-config"

Optionally, you can publish the views using

php artisan vendor:publish --tag="laravel-web-tinker-views"

Or if you want to publish everything at once, you can use

php artisan laravel-web-tinker:install

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.

  1. 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
    });
}
  1. 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 \Luminarix\LaravelWebTinker\OutputModifiers\OutputModifier.

This is how that interface looks like.

namespace Luminarix\LaravelWebTinker\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 and the run-time of the code.

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Credits

License

The MIT License (MIT). Please see License File for more information.