gere-lajos / laravel-web-tinker
Small Laravel package to use Tinker in your browser
Fund package maintenance!
Gere Lajos
Installs: 18
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 2
Forks: 0
Open Issues: 0
Language:TypeScript
Requires
- php: ^8.2
- illuminate/contracts: ^11.0||^10.0
- laravel/framework: ^11.0||^10.0
- nesbot/carbon: ^3.0||^2.63
- spatie/laravel-package-tools: ^1.16
Requires (Dev)
- larastan/larastan: ^2.9
- laravel/pint: ^1.15
- nunomaduro/collision: ^8.1.1||^7.10.0
- orchestra/testbench: ^9.0.0||^8.22.0
- pestphp/pest: ^2.34
- pestphp/pest-plugin-arch: ^2.7
- pestphp/pest-plugin-laravel: ^2.3
- phpstan/extension-installer: ^1.3
- phpstan/phpstan-deprecation-rules: ^1.1
- phpstan/phpstan-phpunit: ^1.3
README
NOTE
We have transitioned the ongoing development of this project to a new repository. You can access it at luminarix/laravel-web-tinker. Please note that this current repository will no longer receive updates.
Small Laravel package to use Tinker in your browser
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
- If you run the code with ctrl+enter or cmd+enter, the editor will also start a new line.
- History is shared between tabs, and is not cleared when you close the tab.
- Big outputs are not handled well, it can push the grid instead of breaking words.
- We must validate the stored code structure so it won't break the editor.
Installation
You can install the package via composer:
composer require gere-lajos/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="GereLajos\LaravelWebTinker\WebTinkerServiceProvider" --tag="config"
This is the content that will be published to config/web-tinker.php
If you previously installed Spatie's Web Tinker, you may have conflicts in the config file. You can safely remove the web-tinker.php
file from the config
directory.
return [ /* * The web tinker page will be available on this path. */ 'path' => '/tinker', /* * 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' => \GereLajos\LaravelWebTinker\OutputModifiers\PrefixDateTime::class, /* * These middleware will be assigned to every WebTinker route, giving you the chance * to add your own middlewares to this list or change any of the existing middleware. */ 'middleware' => [ Illuminate\Cookie\Middleware\EncryptCookies::class, Illuminate\Session\Middleware\StartSession::class, GereLajos\LaravelWebTinker\Http\Middleware\Authorize::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 theAuthServiceProvider
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 theweb-tinker
config file totrue
.
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 \GereLajos\LaravelWebTinker\OutputModifiers\OutputModifier
.
This is how that interface looks like.
namespace GereLajos\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.
Testing
composer test
Credits
License
The MIT License (MIT). Please see License File for more information.