I have a laravel 4 application and in this application I need to define a model with relation to another model 2 times but with discrimination on type.
Example
class Car extends Eloquent{
public function oldDrivers(){
return $this->hasMany('Driver');
}
public function newDrivers(){
return $this->hasMany('Driver');
}
}
so the relation will be the car
Id at the driver
's table, the thing is when I want to get the old drivers only for a certain car, it returns all drivers from both relations.
When looking into it I found because it is the same table, so now I set a type in the Driver
model, now I want my relation to be filtered by this type, so the oldDrivers will be only drivers with the type of oldDrivers and new drivers will be the Drivers with only the newDriver type set,
How can this be done in Laravel ?