質問するログイン新規登録

回答編集履歴

3

修正

2019/10/24 05:33

投稿

退会済みユーザー
answer CHANGED
@@ -11,10 +11,10 @@
11
11
 
12
12
  ```php
13
13
  $companies = Company::all()->map(function ($item, $key){
14
- return $item->pop('stuff_name');
14
+ return $item->pull('stuff_name');
15
15
  });
16
16
  return $companies;
17
17
  ```
18
18
 
19
19
  [https://readouble.com/laravel/6.0/ja/collections.html#method-map](https://readouble.com/laravel/6.0/ja/collections.html#method-map)
20
- [https://readouble.com/laravel/6.0/ja/collections.html#method-pop](https://readouble.com/laravel/6.0/ja/collections.html#method-pop)
20
+ [https://readouble.com/laravel/6.0/ja/collections.html#method-pull](https://readouble.com/laravel/6.0/ja/collections.html#method-pull)

2

修正

2019/10/24 05:33

投稿

退会済みユーザー
answer CHANGED
@@ -10,7 +10,7 @@
10
10
  動作未検証ですが。
11
11
 
12
12
  ```php
13
- $companies = Company::query()->get()->map(function ($item, $key){
13
+ $companies = Company::all()->map(function ($item, $key){
14
14
  return $item->pop('stuff_name');
15
15
  });
16
16
  return $companies;

1

追記

2019/10/24 05:31

投稿

退会済みユーザー
answer CHANGED
@@ -1,4 +1,20 @@
1
1
  ```php
2
2
  $companies = Company::query()->select('id', 'name')->get();
3
3
  return $companies;
4
- ```
4
+ ```
5
+
6
+ ---
7
+
8
+ > 「stuff_name以外」は指示できるのでしょうか?
9
+
10
+ 動作未検証ですが。
11
+
12
+ ```php
13
+ $companies = Company::query()->get()->map(function ($item, $key){
14
+ return $item->pop('stuff_name');
15
+ });
16
+ return $companies;
17
+ ```
18
+
19
+ [https://readouble.com/laravel/6.0/ja/collections.html#method-map](https://readouble.com/laravel/6.0/ja/collections.html#method-map)
20
+ [https://readouble.com/laravel/6.0/ja/collections.html#method-pop](https://readouble.com/laravel/6.0/ja/collections.html#method-pop)