dimanche 23 décembre 2018

Advanced Eloquent/Laravel question. Can't make a MorphPivot Class with a morphMany relation work

I have this class. Which has a morphedByMany relationship

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class OrdenDeElaboracion extends Model
{
    // ... Stuff goes here


    /**
     * Get all of the model variants that are assigned this production order.
     */
    public function variantes()
    {
        return $this->morphedByMany('App\Variante', 'elaborable')
            ->withPivot(['cantidad', 'informacion_adicional', 'informacion_adicional_fabricacion', 'informacion_adicional_instalacion'])
            ->using('App\Elaborable');
    }
}

But now I want that other class App\Elaborable to have relationship with this one App\Estatus so every "variante (product variant)" on the "elaborable (items with the ability to be elaborated)" table could have a "estatus (status)"

<?php

namespace App;

use Illuminate\Database\Eloquent\Relations\MorphPivot;

class Elaborable extends MorphPivot
{
    // ... more stuff here

    /**
     * The relations to automatically populate to the model.
     *
     * @var array
     */
    protected $with = ['estatus'];

    /**
     * Get the status records associated with the order.
     */
    public function estatus()
    {
        return $this->morphMany('App\Estatus', 'modelo');
    }
}

But this does not work for me I don't know why. The MorphPivot class extends from Model so I can't figure out what am I doing wrong



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire