Lumen 迁移 - 具有 table 名称且不是本地键的复数形式的外部 ID

Lumen migration - Foreign Id with a table name that isn't the plural of the local key

如何创建一个 Lumen 迁移,其中一个列引用了一个 table,而该列的名称与列名称不相关?

示例:

下面会抛出 user_destinations 找不到的错误。

$table->foreign('user_destination')->references('id')->on('locations');

$table->foreignId('warehouse_isle_shelf_id')->constrained();

这里的目的是让它寻找 warehouse_isles 而不是 warehouse_isle_shelveswarehouse_isle_shelfs 因为我不确定 Lumen 如何处理单词的复数 who's plurals aren't just采用单数形式并附加 s.

此处的代码应该可以工作,因为您引用了 table 名称 locations:

$table->foreign('user_destination')->references('id')->on('locations');

但是第二行要求Laravel猜名字。这是文档中讨论它的相关部分:

The foreignId method is an alias for unsignedBigInteger while the constrained method will use convention to determine the table and column name being referenced. If your table name does not match the convention, you may specify the table name by passing it as an argument to the constrained method:

$table->foreignId('user_id')->constrained('users');