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

2019-09-17 19:40发布

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.

2条回答
一夜七次
2楼-- · 2019-09-17 20:15

In Laravel 4 you have to set a table property

protected $table = 'foo';

查看更多
Bombasti
3楼-- · 2019-09-17 20:29

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.

查看更多
登录 后发表回答