public function member(){
return $this->hasMany('App\Model\Project\ProjectMember');
}
И потом в контроллере пишу
$project = Project::find(some_id);
$project->member;
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class User extends Model
{
public function projects()
{
return $this->belongsToMany('App\Project', 'project_user');
}
public function getFullNameAttribute()
{
return "{$this->firstname} {$this->lastname}";
}
}
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Project extends Model
{
public function members()
{
return $this->belongsToMany('App\User', 'project_user');
}
}
$id = 1;
$project = Project::find($id);
@foreach ($project->members as $member)
{{ $member->full_name }}
@endforeach