mardi 26 septembre 2017

Eager load related models in Laravel's Revisionable history

Using Laravel 5.4 and the VentureCraft/revisionable package.

I have 3 models: User, Company and Order.

The Order model implements the Revisionable trait:

namespace App\Models;

class Order extends Eloquent {
    use \Venturecraft\Revisionable\RevisionableTrait;

    // ...
}

The User model has a relationship with the Company model:

public function company() {
    return $this->belongsTo('App\Models\Company');
}

And I would like to eager load the company of a user from an order revision. Something like this

$order = Order::with('revisionHistory.user.company')->find(1);

foreach($order->revisionHistory as $revision) {
    $company = $revision->user->company;
}

I've tried overwriting various methods (e.g. revisionHistory and identifiableName) from the Revisionable trait without any luck.



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2hwwCnj
via IFTTT

Aucun commentaire:

Enregistrer un commentaire