2017-06-05 63 views
0

我試圖顯示在我看來數據來自雄辯的關係,但我似乎做了一點點錯誤。 dd顯示集合中的關係,但我不能在我的視圖中正確調用數據。下面是我做了什麼無法顯示關係數據從雄辯的關係

員工模型

public function task() 
{ 
    return $this->hasMany(Task::class); 
} 

任務模型

public function employee() 
{ 
    return $this->belongsTo(Employee::class); 
} 

TaskController

public function index() 
{ 
    $alltask = Task::with('employee')->get(); 

    dd($alltask); 

    /*return view('task.task', compact('alltask', 'empwithtask'));*/ 
} 

任務視圖

@foreach ($alltask as $task) 
<tr> 
    <td>{{ $task->priority }}</td> 
    <td>{{ $task->firstname }}</td> 
    /* this is meant to be the employee.firstname */ 
    <td>{{ $task->title }}</td> 
    <td>{{ $task->begin }}</td> 
</tr> 
@endforeach 

我無法顯示$ task-> firstname,firstname來自employees表。下面是DD的結果的快照

dd capture

如何顯示員工姓名?

回答

1
$task->employee->firstname 
+0

修復它。現在毆打自己不要在週末嘗試這種方式。謝謝 – Mena