iml885203 / laravel5-tinx
在Tinker内部重新加载您的Laravel Tinker会话,并提供first()、find()、where()等更多魔法快捷键!
Requires
- php: >=5.5.9
- illuminate/support: ~5.0
Requires (Dev)
- phpunit/phpunit: ^6.4|^7.0
This package is auto-updated.
Last update: 2024-09-25 18:24:30 UTC
README
此项目是为Laravel 5.1设计的,由Laravel Tinx分叉而来。Laravel Tinx。
Laravel Tinker,re()重新加载。
从Tinker内部重新加载您的会话,并提供first()、find()、where()等更多魔法快捷键!
安装
要安装Tinx,只需通过Composer要求它
composer require --dev iml885203/laravel5-tinx
如果您使用Laravel <=5.4,请在config/app.php中注册Tinx的服务提供者(Laravel >=5.5此操作自动完成查看)
<?php // 'config/app.php' return [ // etc… 'providers' => [ // etc… iml885203\Laravel5Tinx\TinxServiceProvider::class, // etc… ], // etc… ];
使用方法
从命令行运行,而不是运行php artisan tinker,运行
php artisan tinx
重新加载Tinker会话
要重新启动当前会话,只需调用
re()
这将允许您立即测试应用程序代码更改。
别名:reboot()、reload()、restart()。
在重新启动当前会话之前,生成Composer的优化自动加载文件,请调用
reo()
调用reo()相当于在re()之前运行composer dump -o,确保自启动Tinx以来添加到代码库中的任何新类都可以由Laravel Tinker自动别命名/解析。
魔法模型
Tinx会检测您的模型并为以下快捷键做准备
命名策略
Tinx通过您的strategy配置值定义的实例试算快捷键名称。
假设您有两个模型:Car和Crocodile。
如果您的命名strategy设置为pascal(默认),Tinx会在您的会话中定义以下快捷键
- Car:
$c、$c_、c() - Crocodile:
$cr、$cr_、cr()
名称
为您的会话定义的快捷键将在Tinx加载和后续重新加载时显示。
要在任何时候查看您的快捷键,请运行
names()
您的快捷键最初仅显示如果您的会话满足names_table_limit配置值。
要过滤由names()返回的快捷键,只需传递类似这样的筛选词
names(['car', 'user'])
配置
Tinx包含许多有用的配置选项。
要自定义Tinx安装,请运行以下命令发布其配置文件
php artisan vendor:publish --provider="iml885203\Laravel5Tinx\TinxServiceProvider" --tag="config"
发布后,编辑适当的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 'iml885203\Laravel5Tinx\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