How to change the default name of an eloquent column

Asked

Viewed 364 times

2

I am on a project that is in production, and by default when we use a foreign key in eloquent we follow the following "user_id" rule for example to store user id.

Only at the bank I’m working they put this field as "id_user" and I will always make the relationship generates a mistake saying that the field "user_id" not found. How can I make my code understand that the user_id is the id_user in my bank?

inserir a descrição da imagem aqui

1 answer

2


When you declare the relationship between the models you have the second and third parameter of the relationship function to carry out this change to that convention, for example:

public function address() {
    return $this->hasMany('user', 'foreign_key', 'local_key');
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.