last day (15 days later) » 

11:45 PM
0
Q: table not being set in eloquent model

arrowill12I 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 = 'f5host...

 
The model setup looks fine. I'm not sure about this, but can you try F5Host::all() instead of $host = new F5Host; return $host->all();
 
@Razor f5_hosts does not exist that is why I am trying to change the name to 'f5hosts'
@lukasgeiter that returns the same result
 
Okay. Are you sure this line causes the error? Does it go away if you remove it / comment it out?
 
I am not sure what you mean, the error is caused because it is trying to access a non existent DB. I am specifying the correct DB name but laravel does not seem to be setting it. I have used this method of changing a table name before and it works. it is also specified in the documentation.
 
I know that it should work... I wanted to make sure that $host->all() is actually where the error is happening and not some other code. Also you can try $host->getTable() and see what it returns.
 
11:45 PM
moved to a chat
i get f5_hosts
 
Hmm that's weird
Did you copy paste your code into your question? (I want to exclude the possibility of typos in your code)
 
yep
I just tested setting the table on another model and it worked fine
turns out it is some issue with the class name
 
it is?
 
i changed it to F5host and it works fine
lowercase h
no idea why, seems like a bug to me
 
i know why. and its no bug
laravel transforms CamelCase to snake_case for table names
so a capital "H" resulted in "_h"
but thats not really the solution. setting $table should work anyways
 
11:55 PM
yea I agree
 
one last thing you could try... add this to your model:

public function getTable(){
return 'f5hosts';
}
 

  last day (15 days later) »