This is the code ..
public function create()
{
$data = ComponenteFormacion::with(['campo_disciplinar'])
->get();
return $data;
}
I only get the last element of "field_disciplinary" (in the example the last one I receive is "5"), and I need an arrangement with all the elements "field_disciplinary" that belong to "component_formation"
class ComponenteFormacion extends Model
{
protected $primaryKey = 'id';
protected $table = 'COMPONENTE_FORMACION';
protected $fillable = array('componente_formacion');
public function campo_disciplinar(){
return $this->belongsTo('App\Models\CampoDisciplinar','id','componente_formacion_id');
}
}
class CampoDisciplinar extends Model
{
protected $primaryKey = 'id';
protected $table = 'CAMPO_DISCIPLINAR';
protected $fillable = array(
'campo_disciplinar',
'componente_formacion_id'
);
public function componente_formacion(){
return $this->hasMany('App\Models\ComponenteFormacion','id','componente_formacion_id');
}
public function disciplina(){
return $this->belongsTo('App\Models\Disciplina');
}
}