Passed
Push — develop ( dcecff...37402c )
by Septianata
16:01
created

DenominationResource::toArray()   A

Complexity

Conditions 4
Paths 8

Size

Total Lines 32
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 23
c 1
b 0
f 0
dl 0
loc 32
ccs 0
cts 23
cp 0
rs 9.552
cc 4
nc 8
nop 1
crap 20
1
<?php
2
3
namespace App\Http\Resources\DataTables;
4
5
use Illuminate\Http\Resources\Json\JsonResource;
6
use Illuminate\Support\Str;
7
8
/**
9
 * @property \App\Models\Denomination $resource
10
 */
11
class DenominationResource extends JsonResource
12
{
13
    /**
14
     * Transform the resource into an array.
15
     *
16
     * @param  \Illuminate\Http\Request  $request
17
     * @return array
18
     */
19
    public function toArray($request)
20
    {
21
        $elements = [];
22
23
        if ($request->user()->can('view', $this->resource)) {
24
            $elements[] = view('components.datatables.link-show', [
25
                'url' => route('admin.denomination.show', $this->resource),
26
            ])->render();
27
        }
28
29
        if ($request->user()->can('update', $this->resource)) {
30
            $elements[] = view('components.datatables.link-edit', [
31
                'url' => route('admin.denomination.edit', $this->resource),
32
            ])->render();
33
        }
34
35
        if ($request->user()->can('delete', $this->resource)) {
36
            $elements[] = view('components.datatables.link-destroy', [
37
                'url' => route('admin.denomination.destroy', $this->resource),
38
            ])->render();
39
        }
40
41
        return [
42
            'checkbox' => view('components.datatables.checkbox', [
43
                'value' => $this->resource->getKey(),
44
            ])->render(),
45
            'name' => $this->resource->name,
46
            'value' => $this->resource->value_rupiah,
47
            'type' => $this->resource->type_badge,
48
            'is_visible' => $this->resource->is_visible_badge,
49
            'can_order_custom_quantity' => $this->resource->can_order_custom_quantity_badge,
50
            'action' => view('components.datatables.button-group', compact('elements'))->render(),
51
        ];
52
    }
53
}
54