首页 > laravel > 如何覆盖laravel voyager迁移文件?

如何覆盖laravel voyager迁移文件? (How do I override laravel voyager migration files?)

2019-03-04 laravelvoyager

问题

目前我正在我的一个laravel项目中使用laravel voyager我的问题是voyager带有一些开箱即用的迁移文件,这些迁移文件有时会导致与我自己的迁移文件发生冲突,尤其是那些创建用户表的文件,那么它是怎么回事我可以修改voyager迁移文件检查文档只告诉我如何覆盖视图和控制器,但没有关于迁移文件。有些人可以提供完成此任务所需的步骤吗?

解决方法

您可以使用artisan vendor:publish,然后删除/修改您需要的那些来发布它们。

但是,有时库不允许您发布所有文件。我安装了一个快速项目,这似乎是旅行者的情况。显然,您只能发布虚拟迁移。在这种情况下,我只能看到3种可能的方式:

  1. 解决你身边的冲突。这将是更容易和更清洁的方式。
  2. 手动将迁移复制vendor/tcg/voyager/migrations之前database/migrations并使用php artisan migrate php artisan voyager:install
  3. 分叉图书馆并进行更改。不是最好的,你将不得不维护你的分叉和你的应用程序。
  4. 拷贝手动将迁移vendor/tcg/voyager/migrationsdatabase/migrations扩展/倍率 vendor/tcg/voyager/src/VoyagerServiceProvider.php来强制注册的迁移。但我不建议,因为一个小的更新可能会打破你的应用程序。

点2 3和4的附加警告:如果您确实更改了例如Voyager列名,库可能会使用库中的列名,您可能会遇到其他一些问题。我相信你应该调整你的迁移和你的代码库。

问题

Currently I'm using laravel voyager in one of my laravel projects my issue is that voyager comes with some migration files out of the box these migration files sometimes causes conflicts with my own migration files especially that which creates the users table so how is it that i can modify voyager migration files checking the documentation only tells me how to override views and controllers but nothing about migration files. Can some provide the steps you would take to accomplish this task ?

解决方法

You can publish them using artisan vendor:publish, then deleting/modifying the ones you need to.

However, sometime the libraries doesn't allow you to publish all their files. I mounted a quick project and it seems to be the case for voyager. Apparently, you can only publish the dummy migrations. In that case, I can see only 3 possibles way:

  1. Fix the conflict on your side. It will be the easier and cleaner way.
  2. Copy manually the migrations vendor/tcg/voyager/migrations to database/migrations and use php artisan migrate before php artisan voyager:install
  3. Fork the library and do your changes. Not the best, you will have to maintain your fork as well as your app.
  4. Copy manually the migrations vendor/tcg/voyager/migrations to database/migrations then extend/override vendor/tcg/voyager/src/VoyagerServiceProvider.php to force to not register the migrations. But I would'nt recommend, since event a minor update could break your app.

Additional Warning with the points 2 3 and 4: If you do change e.g. a Voyager column name, the library may use the column name in the library and you may encounter some others problem. I do believe you should adapt your migrations and your codebase.

相似信息