4
I cannot access the properties of the related object. Well, I have a class calling for FileClass
, she 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 recover the values as follows:
Reservacontroller.php
public function getIndex(){
$fileClass = FileClass::with(['FileServico'])->get();
return View::make('home')->with('fileClass',$fileClass);
}
However, in the view I cannot access the objects of the relationship, below I list 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 just give a print_r()
in $fileClass
which is the object q returns to view it does not visualize the related object, but if I give a print_r()
in an iterated object with foreach
and try to access its separate property, it accesses normally $f->fileServico
.