0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Laravel:EloquentでgetしたCollectionから特定のキーのみ取得する(重複排除)

Posted at

前提

以下のようなUsersテーブルがあるとする

id company_id name
1 1 aaa
2 2 bbb
3 3 ccc
4 1 ddd
5 2 eee

上記から既に全データを取得しているとする
$users = User::get();

Collectionから特定のキーのみ取得する(重複排除)方法

$usersから会社idだけ取り出したい(重複排除)場合、以下のようにする

$companyIds = $users->pluck('company_id')->unique();

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?