从Tinker内部重新加载你的Laravel Tinker会话,以及first(), find(), where()等更多魔术快捷键!

维护者

详细信息

github.com/andrei930/tinx

源代码

安装: 5,346

依赖者: 0

建议者: 0

安全: 0

星标: 1

观察者: 1

分支: 37

类型:laravel

2.6.3 2020-09-29 08:02 UTC

README

Furey/Tinx的更新版本

原始包链接

在寻找可重新加载的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()loaded.

从Tinker内部重新加载你的会话,以及first(), find(), where()等更多魔术快捷键!

内容

安装

要安装Tinx,只需通过Composer要求它

composer require --dev andrei930/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 -ore()之前,确保自启动Tinx以来添加到你的代码库中的任何新类都可以由Laravel Tinker自动别名/解析。

魔术模型

Tinx扫描你的模型并准备以下快捷键

命名策略

Tinx通过你的strategy配置值定义的实现来计算快捷键名称。

假设你有两个模型:CarCrocodile

如果你的命名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