Is there a way to create an Eloquent relation function based on custom foreign - other key value?
For example I have level relation:
public function level(){
return $this->belongsTo(Level::class, 'level_number', 'number');
}
And I want to do something like this:
public function nextLevel(){
return $this->belongsTo(Level::class)->where('number', '=', $this->level_number + 1);
}
Is this possible or I have to write a raw query?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire