athene athene - 1 month ago 6
PHP Question

Laravel sounds like magic

I just recently started experimenting with laravel, lovely. One thing l dont understand though is how laravel knows my table l just added a model and the model isnt the exact table name, but just how does it manage to get my table,


Reference to Eloquent Model Conventions:

Note that we did not tell Eloquent which table to use for our Flight model. By convention, the "snake case", plural name of the class will be used as the table name unless another name is explicitly specified.

Internally, Laravel does something like this.

$table = $table ?: Str::plural($name);

So it will automatically try to look for the plural of your model name if no $table property is being set.