threeel
3 years ago

How to create a convenient function? is hasManyThrough good for this?

Posted 3 years ago by threeel

i have 3 models

Callee
    id (int)
    name(string)

CalleeMetadata
    id (int)
    callee_id(int)
    callee_meta_type_id (string)
    value(string)
    timestamp

CalleeMetaType
    id (string)
    label(string)

i want to create a function from callee to metatypes and from metatypes to callee

i have tried using hasManythrough like

class Callee extends Model
{

    public function metadata(){
        return $this->hasMany(CalleeMetaData::class);
    }

    public function metatypes(){
        return $this->hasManyThrough(CalleeMetaType::class,CalleeMetaData::class,"callee_meta_type_id","id");
    }

}

but i get an empty collection any input is highly appreciated! thanks

Please sign in or create an account to participate in this conversation.