Всем здравствуйте! Нужна Ваша помощь.
Суть вопроса: как из двух коллекций получить одну, а именно нужно при совпадении поля (id) добавлять у выходную коллекцию поле
"is_follow" => true/false
Пример кода:
$tags = Tag::all();
$user_tags = auth()->user()->tags()->get();
$tags = Tag::all()
- Все теги
$user_tags = auth()->user()->tags()->get()
- Теги на которые подписан текущий пользователь
dd($tags->toArray());
array:50 [
0 => array:6 [
"id" => 1
"icon" => "https://picsum.photos/seed/id/100/100"
"title" => "Id"
"slug" => "id"
"created_at" => "2021-08-06T14:22:15.000000Z"
"updated_at" => "2021-08-06T14:22:15.000000Z"
]
1 => array:6 [
"id" => 3
"icon" => "https://picsum.photos/seed/qui/100/100"
"title" => "Qui"
"slug" => "qui"
"created_at" => "2021-08-06T14:22:15.000000Z"
"updated_at" => "2021-08-06T14:22:15.000000Z"
]
...
]
dd($user_tags->toArray());
array:2 [
0 => array:7 [
"id" => 1
"icon" => "https://picsum.photos/seed/nesciunt/100/100"
"title" => "Nesciunt"
"slug" => "nesciunt"
"created_at" => "2021-08-06T14:22:15.000000Z"
"updated_at" => "2021-08-06T14:22:15.000000Z"
"pivot" => array:2 []
]
1 => array:7 [
"id" => 3
"icon" => "https://picsum.photos/seed/nulla/100/100"
"title" => "Nulla"
"slug" => "nulla"
"created_at" => "2021-08-06T14:22:15.000000Z"
"updated_at" => "2021-08-06T14:22:15.000000Z"
"pivot" => array:2 []
]
Как мне получить коллекцию вида:
array:50 [
0 => array:7 [
"id" => 1
"icon" => "https://picsum.photos/seed/id/100/100"
"is_follow" => true
"title" => "Id"
"slug" => "id"
"created_at" => "2021-08-06T14:22:15.000000Z"
"updated_at" => "2021-08-06T14:22:15.000000Z"
]
1 => array:7 [
"id" => 2
"icon" => "https://picsum.photos/seed/qui/100/100"
"is_follow" => false
"title" => "Qui"
"slug" => "qui"
"created_at" => "2021-08-06T14:22:15.000000Z"
"updated_at" => "2021-08-06T14:22:15.000000Z"
]
2 => array:7 [
"id" => 3
"icon" => "https://picsum.photos/seed/qui/100/100"
"is_follow" => true
"title" => "Qui"
"slug" => "qui"
"created_at" => "2021-08-06T14:22:15.000000Z"
"updated_at" => "2021-08-06T14:22:15.000000Z"
]
...
]
Подскажите, в какую сторону смотреть и какие методы использовать...?