Расширенный Eloquent / Laravel вопрос.Не удается сделать класс MorphPivot с отношением morphMany - PullRequest
0 голосов
/ 24 декабря 2018

У меня есть этот класс.Который имеет отношение morphedByMany

<?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');
    }
}

Но теперь я хочу, чтобы этот другой класс App\Elaborable имел отношения с этим App\Estatus, чтобы каждое "variante (вариант продукта)" на "обрабатываемое (элементыс возможностью уточнения) "таблица может иметь" статус (статус) "

<?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');
    }
}

Но это не работает для меня, я не знаю почему.Класс MorphPivot расширяется от Model, поэтому я не могу понять, что я делаю неправильно

Обновление: Пример кода

Route::get('/get_test', function () {
    $orden_de_elaboracion = OrdenDeElaboracion::findOrFail(1);
    return $orden_de_elaboracion->variantes->map(function ($variante) {
        $newEstatus = new Estatus([]);
        $variante->estatus()->save($newEstatus);
        return $newEstatus->id;
    });
});

С этим явзять это.Например, если отношения не были определены.

enter image description here

Я не знаю, имеет ли это какое-то отношение -> https://github.com/laravel/framework/issues/17770

...