简体   繁体   English

表没有设置在雄辩的模型中

[英]table not being set in eloquent model

I am having some issues setting my table in an eloquent model. 我有一些问题在一个雄辩的模型中设置我的表。 I have done this many times before but for some reason this doesn't seem to be working. 我以前做了很多次,但由于某些原因,这似乎没有起作用。 am I missing something completely here? 我在这里完全错过了什么吗?

Model: 模型:

class F5Host extends Eloquent {


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


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

}

Usage: 用法:

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

Error: 错误:

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

Update: I know Laravel has a feature that translates CamelCase to snake_case when using models to determine the DB table name. 更新:我知道Laravel有一个功能,可以在使用模型确定数据库表名时将CamelCase转换为snake_case。 however the $table variable should override this. 但是$ table变量应该覆盖它。 I noticed when changing the class name to "F5host" all of a sudden the override begins working. 我注意到,当将类名更改为“F5host”时,覆盖开始工作。

Create Environment class model 创建环境类模型

Example

class Environment extends Eloquent {


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


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

}

Change relation methods and test. 改变关系方法和测试。

Sory: My English is not good. 索里:我的英语不好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM