Completed
Push — master ( ce259e...2296bc )
by Elf
01:46
created

EloquentDataTable::addColumn()   C

Complexity

Conditions 7
Paths 12

Size

Total Lines 23
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 56

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 23
ccs 0
cts 10
cp 0
rs 6.7272
cc 7
eloc 12
nc 12
nop 3
crap 56
1
<?php
2
3
namespace ElfSundae\Laravel\DataTables;
4
5
use Yajra\DataTables\EloquentDataTable as BaseEloquentDataTable;
6
7
class EloquentDataTable extends BaseEloquentDataTable
8
{
9
    /**
10
     * Add columns in collection.
11
     *
12
     * @param  array  $names
13
     * @param  bool|int  $order
14
     * @return $this
15
     */
16
    public function addColumns(array $names, $order = false)
17
    {
18
        foreach ($names as $name => $attribute) {
19
            if (is_int($name)) {
20
                $name = $attribute;
21
            }
22
23
            $this->addColumn($name, function ($model) use ($attribute) {
24
                return $model->getAttribute($attribute);
25
            }, is_int($order) ? $order++ : $order);
26
        }
27
28
        return $this;
29
    }
30
}
31