Sayakiss Sayakiss - 1 month ago 20x
PHP Question

Laravel5: Why my model "Media" require table named "media" instead of "medias"?

From the doc of laravel, it claims:

Now, let's look at an example
model, which we will use to retrieve and store information from our
database table

So I wrote:


namespace App;

use Illuminate\Database\Eloquent\Model;

class Media extends Model

And controller:


namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Media;

class MediaController extends Controller
public function index() {
return view('medias.index')->with('medias', Media::all());

But when I query
, it gives that error:

QueryException in Connection.php line 729:
SQLSTATE[42S02]: Base table or view not found: 1146 Table '' doesn't exist (SQL: select * from `media`)

It requires a table named
instead of
as document said. So why that errors happened? Do I accidentally open option flag which changed the default name mapping from model to table or something similar?

Any suggestion will be appreciated.


  • Laravel Framework version 5.2.43

  • PHP


As @FrankProvost said, Laravel (Doctrine, actually) is smart enough and has hardcoded words that should not be inflected:

'Kongoese', 'Lucchese', 'mackerel', 'Maltese', '.*?media',

So, use media table or use protected $table variable to force medias table name.