I'm working on a new project using Laravel where I need to use data from a legacy database(so please ignore the database design).
This database is using the username as primary key:
The User model has a One To Many relationshio with "ChangeContract" model
/**
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function changesContract(): \Illuminate\Database\Eloquent\Relations\HasMany
{
return $this->hasMany(ChangeContract::class, 'Username', 'UserName')->latestFirst();
}
The current user has multiple contract changes:
But only two Contract Changes are returned by the relationship, the ones that matach the primary key(user name) exactly(case sensitive):
"changesContract": [
{
"type": "Contract Change",
"username": "FroneaBA",
"date": "2017-10-01",
"endDate": "2018-06-30"
},
{
"type": "Contract Change",
"username": "FroneaBA",
"date": "2017-07-01",
"endDate": "2017-09-30"
}
],
I need also to return the items where the key is froneaba. Is there a way to set the primary key to be case insensitive?
P.S: From the database client, if I write the query by hand, all the items are returned:
SELECT * FROM changescontract WHERE username='froneaba';