Table not set in eloquent model

I am having problems setting up my table in an eloquent model. I have done this many times, but for some reason this does not seem to work. Am I missing something here?

Model:

class F5Host extends Eloquent {


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


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

}

Using:

  $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 that Laravel has a function that translates CamelCase to snake_case when using models to determine the database table name. however, the $ table variable should override this. I noticed that when changing the class name to "F5host", an override suddenly starts working.

+4
source share
1 answer

Create an environment class model

Example

class Environment extends Eloquent {


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


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

}

Change the methods and tests of relationships.

: .

0

Source: https://habr.com/ru/post/1568679/


All Articles