CristalTeam / php-api-wrapper

:rainbow: Work with APIs like with Laravel Eloquent or Doctrine (no longer a dream)
MIT License
117 stars 32 forks source link

How can I eagerload an ApiRelation on an Eloquent model? Using the laravel bridge. #22

Open BramBosSoliede opened 3 years ago

BramBosSoliede commented 3 years ago

How can I eagerload an ApiRelation on an Eloquent model?

Im doing Offerte::with('klant')->get()

where "Offerte" is an eloquent model which uses "HasApiRelations" "Offerte" has this method:

    public function klant(){
        return $this->belongsTo(Klant::class, 'klant_id');
    }

"Klant" extends ApiModel which in turn extends Cristal\ApiWrapper\Bridges\Laravel\Model

when I run Offerte::with('klant')->get() the response is: "Exception: Call to a member function addEagerConstraints() on array".

What am I doing wrong?

camillebaronnet commented 3 years ago

Hi @BramBosSoliede !

The "with" method in this package is currently not implemented. We are keeping this issue open. You are welcome to contribute if you want to implement this part yourself.

Camille,