I am using laravel 5.3 and I have a scenario as follows
I have 2 models
- Robot
- Location
A Robot can have many Locations but a location can belong to only 1 Robot, and each time a Robot have a new location the count field in location Table will increment
what I am trying to is that I want to use polymorph relation with Laravel and Eloquent, I want to get all the Locations of all Robots by last updated by using distinct() ?
By the way, Locatable_id in location table is refers to Robot ID. here is my models
Robot Model
public function locations() {
return $this->morphMany('App\Models\Location', 'locatable');
}
Location Model
public function locatable() {
return $this->morphTo();
}
Locations Table
Any help would be really appreciated. Thanks.