mercredi 4 juillet 2018

Laravel get relationship

I have a database as follows:

devices -id -name

available_params -id -name

reportable -id -device_id -available_params_id -last_value

My query is based on the Device Model which has:

    public function reportable()
{
    return $this->hasMany(Reportable::class);
}

that works

My Reportable model has:

    public function n4sparameter()
{
    return $this->hasMany(AvailableParams::class,'id','available_params_id');
}

and thats the part that doesn't work.

$device = Device::with(['reportable','reportable.available_params', 'created_by'])->findOrFail($id);

I tried hasMany, belongsTo, and a few others in case I had some relationship wrong.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire