I am curious about how eloquent knows in which table it should save the records we give it by running $ php artisan tinker
. I do not actually remember setting
Actually if you not set the $table
property, Eloquent will automatically look the snake case and plural name of the class name. For example if class name is User
, it will users
.
Here the code taken from Illuminate/Database/Eloquent/Model.php
public function getTable()
{
if (isset($this->table)) {
return $this->table;
}
return str_replace('\\', '', Str::snake(Str::plural(class_basename($this))));
}