I can not access the properties of the related object. Well, I have a class named FileClass
, it has the following relationship with class FileServico
:
FileClass.php
public function fileServico(){
return $this->hasMany('FileServico','id_file','id_file');
}
FileServico.php
public function file(){
return $this->belongsTo('FileClass','id_file','id_file');
}
In my controller I retrieve the values as follows:
ReservationController.php
public function getIndex(){
$fileClass = FileClass::with(['FileServico'])->get();
return View::make('home')->with('fileClass',$fileClass);
}
However, in the view I can not access the objects of the relationship, here are some ways to access that I tried:
@foreach($fileClass as $f)
$f->id_servico; //Tentei assim
$f->file_servico->id_servico //Tentei assim
$f->fileServico->id_servico; //Assim também
$f->id_servico //Assim também
$f->fileServico['id_servico'] //Como array também
$f->fileServico[0]['id_servico'] //Assim...
@endforeach
Understanding better, a file can have several file_servico
, if I simply give a print_r()
to $fileClass
that is the object that returns to view it does not see the related object, however if I give a print_r()
on an object iterated with foreach
and trying to access its separate property, it usually accesses $f->fileServico
.