表未在雄辩模型中设置


table not being set in eloquent model

我在用雄辩的模型中设置我的桌子时遇到了一些问题。我以前做过很多次,但由于某种原因,这似乎不起作用。我在这里完全错过了什么吗?

型:

class F5Host extends Eloquent {

   protected $guarded = array();
   protected $table = 'f5hosts';

   public function Environments() {
      return $this->belongsTo('Environment');
   }
}

用法:

  $host = new F5Host;
  return $host->all();

错误:

SQLSTATE[42S02]: Base table or view not found: 1146 Table 'myapp.f5_hosts' doesn't exist (SQL: select * from `f5_hosts`)

更新:我知道Laravel有一个功能,在使用模型确定数据库表名称时,可以将CamelCase转换为snake_case。但是,$table变量应覆盖此变量。我注意到当将类名更改为"F5host"时,覆盖突然开始工作。

创建环境类模型

class Environment extends Eloquent {

   protected $guarded = array();
   protected $table = 'environment';

   public function f5hosts() {
      return $this->hasOne('F5Host');
   }
}

更改关系方法和测试。

索里:我的英语不好。