i have a problem with reading out data with a relationship. some how it returns Undefined property: IlluminateDatabaseEloquentRelationsHasMany::$id. I have no clue what i did wrong since i just started using laravel.
model 1 Project:
namespace App;
use IlluminateDatabaseEloquentModel;
class Project extends Model
{
protected $table = "project";
public function projectitem()
{
return $this->hasMany('AppProjectitem');
}
}
model 2 Projectitem:
namespace App;
use IlluminateDatabaseEloquentModel;
class Projectitem extends Model
{
protected $table = "project_item";
function project(){
return $this->belongsTo('AppProject');
}
}
index.php
@foreach ($projects as $project)
<tr>
<td>{{$project->projectitem()->id}}</td>
<td></td>
</tr>
@endforeach
i have no clue why this happens, i've tried a couple of solutions but none seems to work.
Any help would be appreciated
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…