Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with eloquent model named as Media #8673

Closed
gabriellimo opened this issue May 9, 2015 · 3 comments
Closed

Problem with eloquent model named as Media #8673

gabriellimo opened this issue May 9, 2015 · 3 comments

Comments

@gabriellimo
Copy link

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"

@lukasgeiter
Copy link
Contributor

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.

@gabriellimo
Copy link
Author

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

@jartaud
Copy link

jartaud commented May 20, 2019

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants