daily pastebin goal
12%
SHARE
TWEET

dd belongsToMany

a guest May 26th, 2018 80 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // trong Model Task
  2.     public function groups() {
  3.         return $this->belongsToMany(Group::class, 'task_group', 'task_id', 'group_id');
  4.     }
  5.  
  6. // trong Controller
  7. $item = Task::find(1)->groups->pluck('name');
  8.  
  9. // ket qua dump bang ham dd($item)
  10. Collection {#332 ▼
  11.  #items: array:2 [▼
  12.    0 => "Nhom 1"
  13.     1 => "Nhom 2"
  14.   ]
  15. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top