I am working on an application where an Item has a value called wavelength. In another table, represented by the model Color, there are many entries in the form of {id | color | start_wavelength | end_wavelength}. I am trying to figure out how to define a relationship in the Item Model that can get the Color based on where it falls in the range.
Essentially what I am needing is to get the color where the start_wavelength is greater or equal to the value of the item's wavelength AND where the end_wavelength value is less than that of the item's wavelength.
This is what I am trying to do currently but it obviously work work because the relationship isn't defined by Primary Keys and Foreign Keys.
public function color()
{
return $this->belongsTo('App\Color')->where('wavelength', '<=', 'end')->where('wavelength', '>=', 'start');
}
Is there a better way to do this or is it even possible?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire