I have the following structure:
class AffiliateRepository extends GenericRepository implements IAffiliateRepository {
}
abstract class GenericRepository {
public function save(BaseModel $model) : int{
$model->save();
return $model->getId();
}
}
interface IAffiliateRepository {
public function save(Affiliate $affiliate) : int;
}
public class Affiliate extends BaseModel{}
$affiliateRepository = new AffiliateRepository();
$affiliateRepository->save(new Affiliate());
I am expecting GenericRepository
to take care on the save action.
but I'm getting the following error:
Declaration of App\Services\AffiliateRepository::save(App\Models\Affiliate $affiliate): int
should be compatible with
App\Services\GenericRepository::save(App\Models\BaseModel $model): int
Why is that? Affiliate
inherits from BaseModel
.
Whats the best way to overcome that and let GenericRepository
handle the save
function call.
thanks