Eloquent: Use another column as primary key on a relationship
Since at least 4.2, you can now specify the local key in the hasMany
.
From the documentation (4.2, 5.2, 5.4, 5.7) :
return $this->hasMany('Comment', 'foreign_key', 'local_key');
Stumbled into the same problem lately, I'm not yet sure whether this would work, but as an idea:
class Book {
public function isbn() {
// instead of hasMany
return ISBN::where('isbn', $this->isbn);
}
}