承接 mattyeend/prevent-destructive-commands 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

mattyeend/prevent-destructive-commands

最新稳定版本:v1.1.9

Composer 安装命令:

composer require mattyeend/prevent-destructive-commands

包简介

A Laravel package to stop destructive commands.

README 文档

README

Prevent Destructive Commands is a Laravel package that disables certain destructive Artisan commands in production environments to protect your database and application data.

Features

This package disables the following commands when the application is in the production environment:

  • php artisan migrate:fresh - Drops all tables and re-runs migrations.
  • php artisan migrate:reset - Rolls back all migrations.
  • php artisan migrate:rollback - Rolls back a batch of migrations.
  • php artisan db:wipe - Drops all databases. In non-production environments, these commands will function as usual.

Installation

  1. Install via Composer: composer require MattYeend/prevent-destructive-commands

Compatibility

This package is compatible with Laravel 10, 11, and 12.

Registration

Laravel 10, 11, and 12

For Laravel 10, 11, and 12, nothing needs to be done to register the package after install.

Usage

The package automatically disables destructive commands in the production environment. No additional setup is required.

Running a Disabled Command in Production

If you attempt to run any of the disabled commands in a production environment, you’ll receive an error message like: This 'migrate:fresh' command is disabled in this environment for safety. In non-production environments (e.g., local, staging), the commands will execute normally.

Environment Configuration

Ensure your .env file correctly specifies the application environment: APP_ENV=production The package determines the current environment using Laravel’s app()->environment() method.

Testing

You can simulate the package behavior by temporarily setting your application environment to production. To do this:

  1. Edit .env
APP_ENV=production
  1. Attempt to run a destructive command, e.g.:
php artisan migrate:fresh
  1. You should see an error message similar to the following:
This 'migrate:fresh' command is disabled in this environment for safety.
Testing through package
  1. Install dependencies
composer install
  1. Run the test
composer test

License

This package is licensed under the MIT License.

Contributing

Feel free to fork the repository and submit pull requests for improvements or new features!

统计信息

  • 总下载量: 89
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-01-09