narcisonunez/laravel-scripts

1.0.1 2021-03-28 05:01 UTC

This package is auto-updated.

Last update: 2024-09-28 12:27:59 UTC


README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

Banner image

Laravel Scripts 允许您创建脚本并管理该脚本是否可以运行。

安装

您可以通过 composer 安装此包

composer require narcisonunez/laravel-scripts

您可以使用以下命令发布和运行迁移

php artisan vendor:publish --provider="Narcisonunez\LaravelScripts\LaravelScriptsServiceProvider" --tag="scripts-migrations"
php artisan migrate

终端使用

###创建脚本 使用 --force 选项覆盖现有类

php artisan scripts:make ScriptName

###功能 您可以通过重写以下属性来自定义脚本:

  • 脚本可以运行的次数。
/**
 * @var int
 */
public int $allowedRuns = 1;

这将确保您只运行一次脚本。默认情况下,它是无限的(0

  • 在事务中运行脚本。
/**
 * @var bool
 */
public bool $runAsTransaction = true;

这将使您的运行方法在事务中运行。默认情况下,它是 false

  • 脚本可以运行的次数。
/**
* @var array
*/
public array $dependenciesValues = [
    'email : The email for the notification',
    'name? : Name of the person running the script',
    'role?'
];

依赖项的格式为:fieldName : Description。在 fieldName 中使用 ? 将使其成为可选的

您可以使用 $this->dependencies->fieldName 在您的脚本类中访问这些值

###运行脚本

php artisan scripts:run ScriptName

使用 --interactive 选项使用您的 dependenciesValues。这将动态要求您输入所有值。

您可以使用 $this->dependencies->fieldName 在您的脚本类中访问这些值

###查看历史记录

php artisan scripts:history [--limit=30] [--script=ScriptName]

默认情况下,--limit 被设置为 10

UI 使用

将此行添加到 routes/web.php 文件中

Route::laravelScripts('scripts');

访问管理界面,请转到浏览器中的 /scripts

  • 您无法通过 UI 创建脚本。

测试

composer test

变更日志

有关最近更改的更多信息,请参阅变更日志

贡献

有关详细信息,请参阅贡献指南

安全漏洞

有关如何报告安全漏洞,请参阅我们的安全策略

致谢

许可

MIT 许可证 (MIT)。有关更多信息,请参阅许可文件