ajthinking / tinx
在Tinker内部重新加载您的Laravel Tinker会话,并提供first()、find()、where()等快捷方式!
Requires
- illuminate/container: ^5.2|^6.0
- laravel/tinker: ~1.0
Requires (Dev)
- phpunit/phpunit: ^6.4|^7.0
This package is auto-updated.
Last update: 2020-05-14 15:38:11 UTC
README
Laravel Tinx 于2019年12月12日归档,不再维护。
在寻找Laravel Tinker的可重新加载版本吗?
将以下脚本保存为 tinx.sh
到项目根目录
#!/bin/sh while true; do php artisan tinker; done
运行脚本以启动可重新加载的Tinker版本
$ . tinx.sh
当您的Tinker会话正在运行时,请按以下键
- Ctrl + D 从空提示符处 重新加载 您的会话
- Ctrl + C 以 退出 您的会话
在Tinker中看不到新创建的类?
退出您的Tinker会话并运行
$ composer dump -o
感谢您喜爱 Laravel,并感谢您挖掘Tinx。
编码愉快!
🤓👋
Laravel Tinx
Laravel Tinker,re() 已重新加载。
从Tinker内部重新加载您的会话,并提供first()、find()、where()等快捷方式!
内容
安装
要安装Tinx,只需通过Composer要求它
composer require --dev ajthinking/tinx
如果您使用Laravel <=5.4,请在 config/app.php
中注册Tinx的服务提供者(Laravel >=5.5 这会自动完成)
<?php // 'config/app.php' return [ // etc… 'providers' => [ // etc… Ajthinking\Tinx\TinxServiceProvider::class, // etc… ], // etc… ];
使用
从命令行运行,而不是运行 php artisan tinker
,请运行
php artisan tinx
重新加载您的Tinker会话
要重新启动当前会话,只需调用
re()
这将使您能够立即测试应用程序代码的更改。
别名:reboot()
、reload()
、restart()
。
在重新启动当前会话之前,先调用以重新生成Composer的优化自动加载文件
reo()
调用 reo()
简单地运行 composer dump -o
在 re()
之前,确保自启动Tinx以来添加到代码库中的任何新类都可以由Laravel Tinker自动别名/解析。
魔法模型
Tinx会扫描您的模型并准备以下快捷方式
示例快捷方式 | 等于 |
---|---|
$u |
App\User::first() |
$u_ |
App\User::latest()->first() |
$c |
App\Models\Car::first() |
u(3) |
App\User::find(3) |
u("gmail") |
任何列中找到 "%gmail%"。 |
u("mail", "jon@snow.com") |
App\User::where("mail", "jon@snow.com")->get() |
u("id", ">", 0) |
App\User::where("id", ">", 0)->get() |
u() |
"App\User" |
u()::whereRaw(...) |
App\User::whereRaw(...) // 注意:仅适用于 PHP 7.0 及以上版本 |
命名策略
Tinx通过您定义的strategy
配置值来计算快捷名称。
假设您有两个模型:Car
和Crocodile
。
如果您的命名strategy
设置为pascal
(默认),Tinx会在您的会话中定义以下快捷名称
- Car:
$c
,$c_
,c()
- Crocodile:
$cr
,$cr_
,cr()
名称
定义的快捷名称将在Tinx加载和后续重新加载时显示。
要在会话期间随时查看您的快捷名称,请运行
names()
您的快捷名称最初只有在您的会话满足names_table_limit
配置值时才会显示。
要过滤由names()
返回的快捷名称,只需传递您的过滤器项,如下所示
names('car', 'user')
快速工厂
快捷方法是一种快速创建工厂模型的好方法。
// Instead of this… factory(App\User::class)->create() // …try substituting a shortcut method, like this: factory(u())->create()
在调试时,每一个键盘敲击都很重要!
配置
Tinx包含许多有用的配置选项。
要定制您的Tinx安装,运行以下命令发布其配置文件:
php artisan vendor:publish --provider=Ajthinking\\Tinx\\TinxServiceProvider --force
发布后,根据需要编辑config/tinx.php
<?php // 'config/tinx.php' return [ /** * Base paths to search for models (paths ending in '*' search recursively). * */ 'model_paths' => [ '/app', '/app/Models/*', // '/also/search/this/directory', // '/also/search/this/directory/recursively/*', ], /** * Only define these models (all other models will be ignored). * */ 'only' => [ // 'App\OnlyThisModel', // 'App\AlsoOnlyThisModel', ], /** * Ignore these models. * */ 'except' => [ // 'App\IgnoreThisModel', // 'App\AlsoIgnoreThisModel', ], /** * Model shortcut naming strategy (e.g. 'App\User' = '$u', '$u_', 'u()'). * Supported values: 'pascal', 'shortestUnique' * */ 'strategy' => 'pascal', /** * Alternatively, you may pass a resolvable fully qualified class name * implementing 'Ajthinking\Tinx\Naming\Strategy'. * */ // 'strategy' => App\CustomNamingStrategy::class, /** * Column name (e.g. 'id', 'created_at') used to determine last model shortcut (i.e. '$u_'). * */ 'latest_column' => 'created_at', /** * If true, models without database tables will also have shortcuts defined. * */ 'tableless_models' => false, /** * Include these file(s) before starting tinker. * */ 'include' => [ // '/include/this/file.php', // '/also/include/this/file.php', ], /** * Show the console 'Class/Shortcuts' table for up to this many model names, otherwise, hide it. * To always view the 'Class/Shortcuts' table regardless of the model name count, * pass a 'verbose' flag when booting Tinx (e.g. "php artisan tinx -v"), * or set this value to '-1'. * */ 'names_table_limit' => 10, ];
贡献
请发布问题和发送PR。
许可证
MIT