mehalubozo's avatar

Get ID in model

How can I get the id of the model from the database in the model itself? In Symphony I always define a method for that. How does Laravel do that?

0 likes
4 replies
bobbybouwmann's avatar
Level 88

All database columns are available as variables inside your model. So you can simple do this everywhere in your model

$this->id;
2 likes
silvester_wali's avatar

i have implement this method in lumen framework but not work as well and also always return null ...any solution sir. thank for your replay

1 like
mabdullahsari's avatar

Eloquent models have a getter called getKey which will return the PK if that's what you mean.

mehalubozo's avatar

I jut needed the id of the user. Thanks for the help

Please or to participate in this conversation.