php-api-wrapper icon indicating copy to clipboard operation
php-api-wrapper copied to clipboard

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

Open BramBosSoliede opened this issue 5 years ago • 1 comments

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?

BramBosSoliede avatar Nov 26 '20 15:11 BramBosSoliede

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,

camillebaronnet avatar Nov 26 '20 20:11 camillebaronnet