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"
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.
Most helpful comment
That's because Laravel is pretty good at figuring out plurals.
media
is already the plural formedium
so Eloquent will assume your table is calledmedia
. Either change that or addprotected $table = 'medias'
to your model.