spatie / laravel-web-tinker
浏览器中的 Artisan Tinker
Requires
- php: ^8.2
- illuminate/cookie: ^10.0|^11.0
- illuminate/session: ^10.0|^11.0
- illuminate/support: ^10.0|^11.0
- laravel/tinker: ^2.0
Requires (Dev)
- orchestra/testbench: ^8.0|^9.0
- phpunit/phpunit: ^9.0|^10.5
README
Artisan 的 tinker 命令是终端中与您的应用程序交互的好方法。不幸的是,运行几行代码、进行编辑以及复制粘贴代码可能会很麻烦。在浏览器中交互会怎么样呢?
此包将为您的应用程序添加一个路由,您可以在其中尽情交互。
如果光线刺眼,还有暗黑模式。
支持我们
我们投入了大量资源来创建 一流的开放源代码包。您可以通过 购买我们的付费产品之一 来支持我们。
我们非常感激您从家乡寄给我们明信片,并说明您正在使用我们的哪个包。您可以在 我们的联系页面 上找到我们的地址。我们将所有收到的明信片发布在我们的 虚拟明信片墙 上。
🚨 有话要说 🚨
此包可以运行任意代码。除非您知道自己在做什么,否则您绝不应该在生产环境中安装或使用此包,或在处理真实世界数据的任何环境中使用。
安装
您可以通过 composer 安装此包。
composer require spatie/laravel-web-tinker --dev
接下来,您必须运行此命令来发布此包中的资源。
php artisan web-tinker:install
可选地,您还可以发布包的配置文件。
php artisan vendor:publish --provider="Spatie\WebTinker\WebTinkerServiceProvider" --tag="config"
这是将被发布到 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, /* * 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, Spatie\WebTinker\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), ];
使用
默认情况下,此包只能在本地环境中运行。
访问您的应用程序本地环境中的 /tinker
来查看 tinker 页面。
授权
如果您想在其他环境中运行此包(我们不推荐这样做),您必须执行两个步骤。
- 您必须在
AuthServiceProvider
中注册一个viewWebTinker
能力。一个好的做法是将它放在与 Laravel 一起提供的AuthServiceProvider
中。
public function boot() { $this->registerPolicies(); Gate::define('viewWebTinker', function ($user = null) { // return true if access to web tinker is allowed }); }
- 您必须在
web-tinker
配置文件中将enabled
变量设置为true
。
修改输出
您可以通过在 web-tinker
配置文件的 output_modifier
键中指定一个输出修改器来修改 tinker 的输出。输出修改器是实现 \Spatie\WebTinker\OutputModifiers\OutputModifier
的任何类。
这个接口看起来是这样的。
namespace Spatie\WebTinker\OutputModifiers; interface OutputModifier { public function modify(string $output = ''): string; }
此包的默认安装将使用 PrefixDataTime
输出修改器,它将在 Tinker 的输出前添加当前日期和时间。
测试
composer test
变更日志
请参阅 CHANGELOG 了解最近更改的详细信息。
贡献
请参阅 CONTRIBUTING 了解详细信息。
安全
如果您发现有关安全性的问题,请通过 security@spatie.be 发送电子邮件,而不是使用问题跟踪器。
鸣谢
此包受到了 nova-tinker-tool 包的启发,并使用了该包中的代码,该包由 Marcel Pociot 开发。
许可证
MIT 许可证(MIT)。有关更多信息,请参阅 许可证文件。