Completed
Push — master ( 2ab8c1...2335cf )
by Elf
01:23
created

Builder::postAjax()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 15
ccs 0
cts 13
cp 0
rs 9.2
cc 4
eloc 8
nc 4
nop 1
crap 20
1
<?php
2
3
namespace ElfSundae\Laravel\DataTables\Html;
4
5
use Illuminate\Support\Arr;
6
use Yajra\DataTables\Html\Builder as BaseBuilder;
7
8
class Builder extends BaseBuilder
9
{
10
    /**
11
     * Setup "ajax" parameter with POST method.
12
     *
13
     * @param  string|array  $attributes
14
     * @return $this
15
     */
16
    public function postAjax($attributes = [])
17
    {
18
        if (! is_array($attributes)) {
19
            $attributes = ['url' => (string) $attributes];
20
        }
21
22
        if (app()->bound('session') && $token = app('session')->token()) {
23
            $attributes = Arr::add($attributes, 'headers.X-CSRF-TOKEN', $token);
24
        }
25
26
        return $this->ajax(array_merge(
27
            Arr::except($attributes, 'method'),
28
            ['type' => 'POST']
29
        ));
30
    }
31
}
32