2015-10-22 150 views
0

我有這個在我的控制器Laravel PHP數組雄辯

$lista = Lesson::where('id', $id_less) 
       ->with(['user' => function ($q) { 
        $q->where('users.id', Auth::user()->id); 
       }]) 
       ->get(); 

輸出爲:

[{"id":2,"id_lessontype":"1","name":"Second lesson","text":"","url1":"","url2":"","created_at":"2015-10-22 03:27:14","updated_at":"2015-10-22 03:27:14","user":[{"status":"Complete","id":2,"name":"licki","email":"[email protected]","created_at":"2015-10-22 12:41:49","updated_at":"2015-10-22 12:41:49","pivot":{"lesson_id":2,"user_id":2,"status_id":1}}]}] 

如何我只能顯示該陣列的狀態

回答

1

你可以這樣做。

$lista = Lesson::where('id', $id_less) 
       ->with(['user' => function ($q) { 
        $q->where('users.id', Auth::user()->id); 
       }]) 
       ->first() 
       ->user 
       ->status; 

$lista = Lesson::find($id_less) 
      ->join('users', 'users.id', '=', 'lesson.id') 
      ->where('users.id', Auth::user()->id) 
      ->pluck('status');