Framework: Problem with eloquent model named as Media

Created on 9 May 2015  路  3Comments  路  Source: laravel/framework

I was having issues in my app with a "Media" model. To check if the problem was in something that I did, I created a fresh Laravel installation. Then I did exactly the following steps:

php artisan make:migration create_medis_table --create=medis
php artisan make:model Medi --no-migration

php artisan make:migration create_medias_table --create=medias
php artisan make:model Media --no-migration

php artisan migrate

serve testing.app /home/vagrant/Projects/testing/public

Then in my routes.php I did:

Route::get('/', function(){

    // dd(\App\Medi::first()); //got null
    dd(\App\Media::first()); //got the following error

});
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'homestead.media' doesn't exist (SQL: select * from `media` limit 1)

Did I something wrong?

PS: I created Medi model just as a "control group"

Most helpful comment

That's because Laravel is pretty good at figuring out plurals. media is already the plural for medium so Eloquent will assume your table is called media. Either change that or add protected $table = 'medias' to your model.

All 3 comments

That's because Laravel is pretty good at figuring out plurals. media is already the plural for medium so Eloquent will assume your table is called media. Either change that or add protected $table = 'medias' to your model.

I already set $table property. Was just trying to understand why was that happening. Thank you so much!

Thanks! just loosing a couple hours trying to figure out why my "Equipment" model was not working.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lzp819739483 picture lzp819739483  路  3Comments

JamborJan picture JamborJan  路  3Comments

PhiloNL picture PhiloNL  路  3Comments

YannPl picture YannPl  路  3Comments

progmars picture progmars  路  3Comments