Laravel 4: Eloquent::find() doesn't work

只谈情不闲聊 提交于 2019-12-12 05:20:08

问题


So I have a simple, empty Eloquent class: class Worker extends Eloquent {}. Then in the controller I write: Worker::find(1); and I get an exception, saying that the SQL is incorrect:

select * where `id` = ?

Obviously, the from SQL clause is missing.

Oh, I downloaded the Laravel 4 for this app today.


回答1:


In Laravel 4 you have to set a table property

protected $table = 'foo';




回答2:


As already mentioned, you have to specifically set a $table property on the model. Taylor has mentioned here that the old way of doing things (a default table name as the plural of the model's name) may be returning. There just isn't a good composer package for pluralising, so the L3 code may be ported.



来源:https://stackoverflow.com/questions/14284854/laravel-4-eloquentfind-doesnt-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!