代码之家  ›  专栏  ›  技术社区  ›  steros

当路由中间件在测试期间从不存在的表中选择时,迁移失败

  •  0
  • steros  · 技术社区  · 8 年前

    我无法运行测试,因为迁移失败,因为在迁移过程中(甚至在迁移开始之前)需要创建的迁移过程中,路由中间件会从表中进行查询。

    我试着用 ->withoutMiddleware() ->withoutMiddleware(ThatMiddleware::class) 没有多少成功。

    因此,我目前的解决方法如下。在所讨论的中间件中,我这样做:

    class ThatMiddleware extends ServiceProvider {
        public function boot() {
            if(Schema::hasTable('table_in_question')) {
                // ... code that queries the table
            }
        }
    }
    

    但这似乎有点不安全,尤其是考虑到中间件是用于身份验证的。 我不确定这个错误是由于编写糟糕的中间件或测试导致的。

    有没有更好的方法来解决这个问题?

    0 回复  |  直到 8 年前