Alex Chiang
Alex Chiang

Reputation: 1840

Method find error with with Eloquent in Lumen

I have a table Order and make a eloquent. The id (primary key) is not int, but varchar.

    $order=Order::find($id);// well, it works.

It works fine, and var_dump the data is right. The question is quote the property is wrong. I mean:

    var_dump($order->id); // get int(0), actually it a varchar in 32 characters
    var_dump($order->remark); // works well

So, i think there is something wrong when id is not int if use eloquent?

Upvotes: 0

Views: 521

Answers (1)

Jarek Tkaczyk
Jarek Tkaczyk

Reputation: 81187

All you need is public $incrementing = false; in your model.

Eloquent by default casts id (its $primaryKey in particular) to int, unless you explicitly state that you don't use auto incrementing ids.

Upvotes: 2

Related Questions