Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在创建一个包并希望在其中包含 db 种子。所有这些种子都会将一些新行添加到已经存在的表中。我还想要一个“取消种子”选项来在卸载包时删除这些行。
我不确定该怎么做?什么是最佳实践?
谢谢
最简单的选项是像往常一样创建一个种子类,并指示用户db:seed使用其--class[=CLASS]选项运行命令。
db:seed
--class[=CLASS]
例如,您的包可能包含MyPackage\Seeds\Install用于添加行和MyPackage\Seeds\Remove删除行的种子类。您的软件包的用户可以使用以下命令运行这些种子:
MyPackage\Seeds\Install
MyPackage\Seeds\Remove
php artisan db:seed --class="MyPackage\Seeds\Install" php artisan db:seed --class="MyPackage\Seeds\Remove"