Relationship in Laravel / Eloquent ORM

3

I have a problem. I need to return the values of a relationship, however, it has the following error:

ErrorException
Undefined property: Illuminate\Database\Eloquent\Collection::$fileServico

My code:

FileClass.php

public function fileServico(){
    return $this->hasMany('File');
}

FileServico.php

public function file(){
    return $this->belongsTo('File');
}

You can have multiple FileServices for a FileClass. As I'm calling:

ReservationController.php

public function getIndex(){
    return View::make('home')->with('file',FileClass::all()->fileServico);
}
    
asked by anonymous 05.06.2014 / 05:36

1 answer

2

That

FileClass::all()->fileServico

It does not work. In case to get the fileServico of each FileClass , it would have to be in an iteration:

foreach( FileClass::all() as $item ){
    var_dump( $item->fileservico );
}
    
05.06.2014 / 06:11