Completed
Pull Request — master (#91)
by
unknown
06:31
created

CartCollection::associate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 11
rs 9.4285
cc 1
eloc 6
nc 1
nop 2
1
<?php namespace Darryldecode\Cart;
2
3
use Illuminate\Support\Collection;
4
5
class CartCollection extends Collection {
6
7
    public function associate($model, $field = 'id'){
8
9
        $associated = new $model;
10
11
        $this->transform(function($item, $key) use ($associated, $field) {
12
            $item['association'] = $associated->where($field,$key)->first();
13
            return $item;
14
        });
15
16
        return $this;
17
    }
18
19
}