i have a problem with reading out data with a relationship. some how it returns Undefined property: Illuminate\Database\Eloquent\Relations\HasMany::$id. I have no clue what i did wrong since i just started using laravel.
model 1 Project:
namespace App;
use Illuminate\Database\Eloquent\Model;
class Project extends Model
{
protected $table = "project";
public function projectitem()
{
return $this->hasMany('App\Projectitem');
}
}
model 2 Projectitem:
namespace App;
use Illuminate\Database\Eloquent\Model;
class Projectitem extends Model
{
protected $table = "project_item";
function project(){
return $this->belongsTo('App\Project');
}
}
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