1

I want to get all Address IDs, including the trashed ones, with pluck. This is how it is working but I don't get the trashed ones as well...:

$clientIDs = Client::pluck('address_id')->all();

This is what I tried already:

$clientIDs = Client::pluck('address_id')
                        ->withTrashed()
                        ->get();

Throws: Method withTrashed does not exist.

How can I use pluck and withTrashed() and solve this problem?

Kind regards!

Jan
  • 1,180
  • 3
  • 23
  • 60

1 Answers1

5

pluck() already finalises the query and retrieves the info from the database for you. So the ->all() call is redundant for that - what it does is convert the Eloquent collection into an array.

For that reason, you're calling withTrashed() after the query has already been executed. Move them and it'll work:

$clientIds = Client::withTrashed()->pluck('address_id'); // no need for ->get()
Joel Hinz
  • 24,719
  • 6
  • 62
  • 75