I have a model that I want to sort based on a relationship property.
- First model "DeviceType":
public function make()
{
return $this->hasMany(DeviceMake::class);
}
- Second model: "DeviceMake":
public function type()
{
return $this->hasOne(DeviceType::class, 'id', 'device_type_id');
}
public function model()
{
return $this->hasMany(DeviceModel::class);
}
- Controller:
$type = DeviceType::with(['make'])->where('id', '=', $device_type_id)->first();
- Table name is
device_makes
and I want to sort it byname
. How can I do this?