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

只有表存在时才使用Laravel查询模型

  •  0
  • Sammaye  · 技术社区  · 7 年前

    所以我有一个 boot() 在我的 AuthServiceProvider Permission 来自数据库:

        foreach (Permission::all() as $perm) {
            Gate::define($perm->name, function ($user) use ($perm) {
                return $user->hasPermission($perm->name);
            });
        }
    

    migrate:fresh 所有的东西都坏了(只有一个例外),因为,嗯,桌子不存在。

    我怎么知道 许可 仅在表存在时加载数据的模型?

    0 回复  |  直到 7 年前
        1
  •  2
  •   Travis Britz    7 年前

    要回答所问的问题,可以使用以下命令:

    if (Schema::hasTable('mytable')) {
    
    }
    

    authorization 那不会引起这样的问题。

    推荐文章