问题
I have a Product.php file in app/models folder. Here is the content of the file:
class Product extends Eloquent{
protected $table = 'productinfo';
}
However, when I tried to run $product = Product::all();
, Laravel say Call to undefined method Product::all()
. It seems like Eloquent class is not extended.
I don't see anything I do wrong here. Why does it not working? Could it be any other configuration in Laravel which I mess up?
--update--
After renaming the Product.php file, it is now no longer showing error message. But the problem is, it does not properly return the result from database. Instead, the returned result is {"incrementing":true,"timestamps":true,"exists":true}
. Not the result from database.
So, I tried to run a clean new Laravel project from composer and the only files that I modified is the config/database.php
file to set it work with MySQL database, route.php
file, and the models/Products.php
file. When I browse it on browser, again it shows the same result: {"incrementing":true,"timestamps":true,"exists":true}
, not database result.
I really don't know what causing it. I have tried with it in one my experiment Laravel project folder which has lots of junk in it, and it works perfectly fine here.
Do you know why it doesn't work? How to solve it?
Thank you.
来源:https://stackoverflow.com/questions/20061876/laravel-4-does-not-extend-eloquent-class