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

EloquentDataTable::addColumns()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 14
ccs 0
cts 12
cp 0
rs 9.2
cc 4
eloc 8
nc 3
nop 2
crap 20
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