I have 2 collections. Vehicles and Views. I would like to bring back a list of vehicles sorted by the number of views.
My Vehicle class
class Vehicle extends Moloquent {
protected $dates = ['date_assigned'];
public function associated_views()
{
return $this->hasMany('App\Collections\View');
}
}
And my View class
class View extends Moloquent {
public function associated_vehicle()
{
return $this->belongsTo('App\Collections\Vehicle');
}
}
I can get the count of the views after the fact, with $vehicle->associated_views->count(), but this doesn't enable me to sort on the field before pulling back every single record. Is this possible?