Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

hank's avatar
Level 1

Usign Eloquent - 's' is added to database table names

I am following this tutorial: https://www.youtube.com/watch?v=_s6K-3KT5wQ

And working on my first Laravel App.

But I have noticed that when I create a new class file (in this case "App\UserInfo"

and then try to pull information to the controller it adds an 's' to the end of the table name. Just wondering if anybody has any idea as to why it is doing this?

Here is the error: (I am trying to work with the table "UserInfo" and instead it seems to be looking for "UserInfos" SQLSTATE[42S02]: Base table or view not found: 1146 Table 'app.UserInfos' doesn't exist (SQL: select * from UserInfos)


use Illuminate\Database\Eloquent\Model as Eloquent;

class UserInfo extends Eloquent {

}


namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests; use App\Http\Controllers\Controller;

use App\UserInfo

class UserInfoController extends Controller { public function index() {

    $users = UserInfo::get();
    
    return view('dashboard.users.list', compact('users'));
}

}

0 likes
9 replies
zachleigh's avatar

This is default behavior. The table is, after all, a table of multiple users, not just one user.

1 like
nathanrobjohn's avatar

Ignore me sorry

protected $table = "userinfo";

Try that in your model

Snapey's avatar

@DuartePinguim but it is not best practice. Conventionally your tables should be plural. Laravel is trying to encourage you to stick to conventions.

pmall's avatar

Just wondering if anybody has any idea as to why it is doing this?

Because it is the normal convention, singular model names, plural table names.

You can override this by specifying your own table name in the table attribute of your eloquent model. public $table = 'your_table_name'.

2 likes
aktolman's avatar

It still does this. If I create a project with 50 tables I have to edit 50 migration files... very annoying. It should give you the choice... maybe it does mind and I have just not found it ;)

Snapey's avatar

@aktolman

It still does this. If I create a project with 50 tables I have to edit 50 migration files... very annoying.

But you have to edit the migrations anyway?

yos_gani's avatar

I think Nathan's suggestion is the very best way to get away from this whatsoever "restriction"

Just use

protected $table = "tablename";

inside ur model class

Please or to participate in this conversation.