Thursday, March 30, 2017

Laravel : Removing an element from a collection array

i use a variable called $users to "pluck" only the emails from my users table, using:

$users = user::all()->pluck('email');

when i dd($users), i get this

<pre>
Collection {#214 ▼
  #items: array:8 [▼
    0 => "adminone@example.com"
    1 => "admintwo@example.com"
    2 => "Adobot@example.com"
    3 => "Lawly@example.com"
    4 => "Cerms@example.com"
    5 => "Charlie@example.com"
    6 => "test@example.com"
    7 => "test001@example.com"
  ]
}
</pre>

meaning that $users isn't purely an array, i get various types of errors when i treat it like an array.

my question is, in php (in a Laravel Framework) how do i remove a specific user's email from the variable above? or is there a better way to use "pluck" so that it returns an array instead?

thanks in advance.



via Kevin fu

Advertisement