How does Laravel find plural of models? -


if have model "dog", laravel link table "dogs". plural. now, if have model "person", tries find table "people" - plural. how laravel know plural when it's more adding "s"? there tabel english nouns?

in illuminate\database\eloquent\model.php you'll find str_plural($name) , str_plural helper function uses str::plural method , in case, method looks this:

public static function plural($value, $count = 2) {     return pluralizer::plural($value, $count); } 

so it's obvious that, str::plural uses class illuminate\support\pluralizer.php , there you'll find how works. read source code. there separate word mapping irregular word forms others:

// taken illuminate\support\pluralizer public static $irregular = array(     'child' => 'children',     'foot' => 'feet',     'freshman' => 'freshmen',     'goose' => 'geese',     'human' => 'humans',     'man' => 'men',     'move' => 'moves',     'person' => 'people',     'sex' => 'sexes',     'tooth' => 'teeth', ); 

Comments

Popular posts from this blog

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

php - render data via PDO::FETCH_FUNC vs loop -

The canvas has been tainted by cross-origin data in chrome only -