I noticed that whenever I create a class using database information in Laravel, the table name must be plural. Why is this?
They don't have to be plural. To make things easy, by default, Eloquent assumes that, if you have a model User
, your database table for it will be users
. However, if you want to have another name for your table, you can specify custom tables for your models, by defining a table
property. For ex:
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class User extends Model
{
protected $table = 'user';
...
}
This will tell Eloquent to use the table user
on your database when working with the model User
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With