2017-03-07 105 views

回答

1

嘗試:

$users = User::pluck('email','id'); 
0

試試這個

$users = User::all(); 
 
$data = array(); 
 
foreach ($users as $key) { 
 
    $data[$key->id] = $key->email; 
 
} 
 
print_r($data);

好運...

1

可以達到這樣,

$users = User::pluck("email","id"); 

pluck() - >你也可以指定你多麼希望得到的集合被鍵入:

有替代做到這一點(與集合打),

$users = User::all()->get(); 
$users = $users->pluck("email","id"); 

試試看吧,這將工作。