merge()正在替换第一个集合

时间:2017-07-17 13:48:21

标签: php laravel collections merge

我想保留每个集合的所有元素。我该怎么做?

我试过了:

$fields = Field::all();
$custom_fields = CustomField::all();
$merged_fields = $fields->merge($custom_fields);

但是此代码似乎正在替换$fields的第一个元素,因为$custom_fields目前只有1个值。

以下是集合的转储:

Illuminate\Database\Eloquent\Collection Object
(
    [items:protected] => Array
        (
            [0] => App\Field Object
                (
                    [fillable:protected] => Array
                        (
                            [0] => label
                            [1] => name
                            [2] => input_type
                            [3] => input_options
                            [4] => show_in_tables
                            [5] => sort
                        )

                    [hidden:protected] => Array
                        (
                            [0] => pivot
                        )

                    [connection:protected] => mysql
                    [table:protected] => 
                    [primaryKey:protected] => id
                    [keyType:protected] => int
                    [incrementing] => 1
                    [with:protected] => Array
                        (
                        )

                    [withCount:protected] => Array
                        (
                        )

                    [perPage:protected] => 15
                    [exists] => 1
                    [wasRecentlyCreated] => 
                    [attributes:protected] => Array
                        (
                            [id] => 1
                            [label] => First Name
                            [name] => first_name
                            [input_type] => 4
                            [input_options] => 
                            [show_in_tables] => 1
                            [sort] => 1
                            [created_at] => 2017-07-17 00:20:59
                            [updated_at] => 2017-07-17 00:20:59
                        )

                    [original:protected] => Array
                        (
                            [id] => 1
                            [label] => First Name
                            [name] => first_name
                            [input_type] => 4
                            [input_options] => 
                            [show_in_tables] => 1
                            [sort] => 1
                            [created_at] => 2017-07-17 00:20:59
                            [updated_at] => 2017-07-17 00:20:59
                        )

                    [casts:protected] => Array
                        (
                        )

                    [dates:protected] => Array
                        (
                        )

                    [dateFormat:protected] => 
                    [appends:protected] => Array
                        (
                        )

                    [events:protected] => Array
                        (
                        )

                    [observables:protected] => Array
                        (
                        )

                    [relations:protected] => Array
                        (
                        )

                    [touches:protected] => Array
                        (
                        )

                    [timestamps] => 1
                    [visible:protected] => Array
                        (
                        )

                    [guarded:protected] => Array
                        (
                            [0] => *
                        )

                )

            [1] => App\Field Object
                (
                    [fillable:protected] => Array
                        (
                            [0] => label
                            [1] => name
                            [2] => input_type
                            [3] => input_options
                            [4] => show_in_tables
                            [5] => sort
                        )

                    [hidden:protected] => Array
                        (
                            [0] => pivot
                        )

                    [connection:protected] => mysql
                    [table:protected] => 
                    [primaryKey:protected] => id
                    [keyType:protected] => int
                    [incrementing] => 1
                    [with:protected] => Array
                        (
                        )

                    [withCount:protected] => Array
                        (
                        )

                    [perPage:protected] => 15
                    [exists] => 1
                    [wasRecentlyCreated] => 
                    [attributes:protected] => Array
                        (
                            [id] => 2
                            [label] => Last Name
                            [name] => last_name
                            [input_type] => 4
                            [input_options] => 
                            [show_in_tables] => 1
                            [sort] => 2
                            [created_at] => 2017-07-17 00:20:59
                            [updated_at] => 2017-07-17 00:20:59
                        )

                    [original:protected] => Array
                        (
                            [id] => 2
                            [label] => Last Name
                            [name] => last_name
                            [input_type] => 4
                            [input_options] => 
                            [show_in_tables] => 1
                            [sort] => 2
                            [created_at] => 2017-07-17 00:20:59
                            [updated_at] => 2017-07-17 00:20:59
                        )

                    [casts:protected] => Array
                        (
                        )

                    [dates:protected] => Array
                        (
                        )

                    [dateFormat:protected] => 
                    [appends:protected] => Array
                        (
                        )

                    [events:protected] => Array
                        (
                        )

                    [observables:protected] => Array
                        (
                        )

                    [relations:protected] => Array
                        (
                        )

                    [touches:protected] => Array
                        (
                        )

                    [timestamps] => 1
                    [visible:protected] => Array
                        (
                        )

                    [guarded:protected] => Array
                        (
                            [0] => *
                        )

                )

            [2] => App\Field Object
                (
                    [fillable:protected] => Array
                        (
                            [0] => label
                            [1] => name
                            [2] => input_type
                            [3] => input_options
                            [4] => show_in_tables
                            [5] => sort
                        )

                    [hidden:protected] => Array
                        (
                            [0] => pivot
                        )

                    [connection:protected] => mysql
                    [table:protected] => 
                    [primaryKey:protected] => id
                    [keyType:protected] => int
                    [incrementing] => 1
                    [with:protected] => Array
                        (
                        )

                    [withCount:protected] => Array
                        (
                        )

                    [perPage:protected] => 15
                    [exists] => 1
                    [wasRecentlyCreated] => 
                    [attributes:protected] => Array
                        (
                            [id] => 3
                            [label] => Email
                            [name] => email
                            [input_type] => 4
                            [input_options] => 
                            [show_in_tables] => 1
                            [sort] => 3
                            [created_at] => 2017-07-17 00:20:59
                            [updated_at] => 2017-07-17 00:20:59
                        )

                    [original:protected] => Array
                        (
                            [id] => 3
                            [label] => Email
                            [name] => email
                            [input_type] => 4
                            [input_options] => 
                            [show_in_tables] => 1
                            [sort] => 3
                            [created_at] => 2017-07-17 00:20:59
                            [updated_at] => 2017-07-17 00:20:59
                        )

                    [casts:protected] => Array
                        (
                        )

                    [dates:protected] => Array
                        (
                        )

                    [dateFormat:protected] => 
                    [appends:protected] => Array
                        (
                        )

                    [events:protected] => Array
                        (
                        )

                    [observables:protected] => Array
                        (
                        )

                    [relations:protected] => Array
                        (
                        )

                    [touches:protected] => Array
                        (
                        )

                    [timestamps] => 1
                    [visible:protected] => Array
                        (
                        )

                    [guarded:protected] => Array
                        (
                            [0] => *
                        )

                )

            [3] => App\Field Object
                (
                    [fillable:protected] => Array
                        (
                            [0] => label
                            [1] => name
                            [2] => input_type
                            [3] => input_options
                            [4] => show_in_tables
                            [5] => sort
                        )

                    [hidden:protected] => Array
                        (
                            [0] => pivot
                        )

                    [connection:protected] => mysql
                    [table:protected] => 
                    [primaryKey:protected] => id
                    [keyType:protected] => int
                    [incrementing] => 1
                    [with:protected] => Array
                        (
                        )

                    [withCount:protected] => Array
                        (
                        )

                    [perPage:protected] => 15
                    [exists] => 1
                    [wasRecentlyCreated] => 
                    [attributes:protected] => Array
                        (
                            [id] => 4
                            [label] => Phone
                            [name] => phone
                            [input_type] => 4
                            [input_options] => 
                            [show_in_tables] => 0
                            [sort] => 4
                            [created_at] => 2017-07-17 00:20:59
                            [updated_at] => 2017-07-17 00:20:59
                        )

                    [original:protected] => Array
                        (
                            [id] => 4
                            [label] => Phone
                            [name] => phone
                            [input_type] => 4
                            [input_options] => 
                            [show_in_tables] => 0
                            [sort] => 4
                            [created_at] => 2017-07-17 00:20:59
                            [updated_at] => 2017-07-17 00:20:59
                        )

                    [casts:protected] => Array
                        (
                        )

                    [dates:protected] => Array
                        (
                        )

                    [dateFormat:protected] => 
                    [appends:protected] => Array
                        (
                        )

                    [events:protected] => Array
                        (
                        )

                    [observables:protected] => Array
                        (
                        )

                    [relations:protected] => Array
                        (
                        )

                    [touches:protected] => Array
                        (
                        )

                    [timestamps] => 1
                    [visible:protected] => Array
                        (
                        )

                    [guarded:protected] => Array
                        (
                            [0] => *
                        )

                )

            [4] => App\Field Object
                (
                    [fillable:protected] => Array
                        (
                            [0] => label
                            [1] => name
                            [2] => input_type
                            [3] => input_options
                            [4] => show_in_tables
                            [5] => sort
                        )

                    [hidden:protected] => Array
                        (
                            [0] => pivot
                        )

                    [connection:protected] => mysql
                    [table:protected] => 
                    [primaryKey:protected] => id
                    [keyType:protected] => int
                    [incrementing] => 1
                    [with:protected] => Array
                        (
                        )

                    [withCount:protected] => Array
                        (
                        )

                    [perPage:protected] => 15
                    [exists] => 1
                    [wasRecentlyCreated] => 
                    [attributes:protected] => Array
                        (
                            [id] => 5
                            [label] => Postal Code
                            [name] => postal_code
                            [input_type] => 4
                            [input_options] => 
                            [show_in_tables] => 0
                            [sort] => 5
                            [created_at] => 2017-07-17 00:20:59
                            [updated_at] => 2017-07-17 00:20:59
                        )

                    [original:protected] => Array
                        (
                            [id] => 5
                            [label] => Postal Code
                            [name] => postal_code
                            [input_type] => 4
                            [input_options] => 
                            [show_in_tables] => 0
                            [sort] => 5
                            [created_at] => 2017-07-17 00:20:59
                            [updated_at] => 2017-07-17 00:20:59
                        )

                    [casts:protected] => Array
                        (
                        )

                    [dates:protected] => Array
                        (
                        )

                    [dateFormat:protected] => 
                    [appends:protected] => Array
                        (
                        )

                    [events:protected] => Array
                        (
                        )

                    [observables:protected] => Array
                        (
                        )

                    [relations:protected] => Array
                        (
                        )

                    [touches:protected] => Array
                        (
                        )

                    [timestamps] => 1
                    [visible:protected] => Array
                        (
                        )

                    [guarded:protected] => Array
                        (
                            [0] => *
                        )

                )

            [5] => App\Field Object
                (
                    [fillable:protected] => Array
                        (
                            [0] => label
                            [1] => name
                            [2] => input_type
                            [3] => input_options
                            [4] => show_in_tables
                            [5] => sort
                        )

                    [hidden:protected] => Array
                        (
                            [0] => pivot
                        )

                    [connection:protected] => mysql
                    [table:protected] => 
                    [primaryKey:protected] => id
                    [keyType:protected] => int
                    [incrementing] => 1
                    [with:protected] => Array
                        (
                        )

                    [withCount:protected] => Array
                        (
                        )

                    [perPage:protected] => 15
                    [exists] => 1
                    [wasRecentlyCreated] => 
                    [attributes:protected] => Array
                        (
                            [id] => 6
                            [label] => Likes Cats
                            [name] => likes_cats
                            [input_type] => 1
                            [input_options] => Yes
No
Maybe
                            [show_in_tables] => 1
                            [sort] => 6
                            [created_at] => 2017-07-17 06:21:42
                            [updated_at] => 2017-07-17 06:21:42
                        )

                    [original:protected] => Array
                        (
                            [id] => 6
                            [label] => Likes Cats
                            [name] => likes_cats
                            [input_type] => 1
                            [input_options] => Yes
No
Maybe
                            [show_in_tables] => 1
                            [sort] => 6
                            [created_at] => 2017-07-17 06:21:42
                            [updated_at] => 2017-07-17 06:21:42
                        )

                    [casts:protected] => Array
                        (
                        )

                    [dates:protected] => Array
                        (
                        )

                    [dateFormat:protected] => 
                    [appends:protected] => Array
                        (
                        )

                    [events:protected] => Array
                        (
                        )

                    [observables:protected] => Array
                        (
                        )

                    [relations:protected] => Array
                        (
                        )

                    [touches:protected] => Array
                        (
                        )

                    [timestamps] => 1
                    [visible:protected] => Array
                        (
                        )

                    [guarded:protected] => Array
                        (
                            [0] => *
                        )

                )

        )

)
Illuminate\Database\Eloquent\Collection Object
(
    [items:protected] => Array
        (
            [0] => App\CustomField Object
                (
                    [fillable:protected] => Array
                        (
                            [0] => label
                            [1] => name
                            [2] => php_code
                        )

                    [connection:protected] => mysql
                    [table:protected] => 
                    [primaryKey:protected] => id
                    [keyType:protected] => int
                    [incrementing] => 1
                    [with:protected] => Array
                        (
                        )

                    [withCount:protected] => Array
                        (
                        )

                    [perPage:protected] => 15
                    [exists] => 1
                    [wasRecentlyCreated] => 
                    [attributes:protected] => Array
                        (
                            [id] => 1
                            [label] => Is Kevin
                            [name] => is_kevin
                            [php_code] => if ($lead->data('first_name') == 'Kevin') {
    return 'Rules';
}
else {
    return 'Drools';
}
                            [created_at] => 2017-07-17 05:18:27
                            [updated_at] => 2017-07-17 06:29:27
                        )

                    [original:protected] => Array
                        (
                            [id] => 1
                            [label] => Is Kevin
                            [name] => is_kevin
                            [php_code] => if ($lead->data('first_name') == 'Kevin') {
    return 'Rules';
}
else {
    return 'Drools';
}
                            [created_at] => 2017-07-17 05:18:27
                            [updated_at] => 2017-07-17 06:29:27
                        )

                    [casts:protected] => Array
                        (
                        )

                    [dates:protected] => Array
                        (
                        )

                    [dateFormat:protected] => 
                    [appends:protected] => Array
                        (
                        )

                    [events:protected] => Array
                        (
                        )

                    [observables:protected] => Array
                        (
                        )

                    [relations:protected] => Array
                        (
                        )

                    [touches:protected] => Array
                        (
                        )

                    [timestamps] => 1
                    [hidden:protected] => Array
                        (
                        )

                    [visible:protected] => Array
                        (
                        )

                    [guarded:protected] => Array
                        (
                            [0] => *
                        )

                )

        )

)

0 个答案:

没有答案