1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Http\Resources\DataTables; |
4
|
|
|
|
5
|
|
|
use Illuminate\Http\Resources\Json\JsonResource; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* @property \App\Models\Denomination $resource |
9
|
|
|
*/ |
10
|
|
|
class DenominationResource extends JsonResource |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* Transform the resource into an array. |
14
|
|
|
* |
15
|
|
|
* @param \Illuminate\Http\Request $request |
16
|
|
|
* @return array |
17
|
|
|
*/ |
18
|
|
|
public function toArray($request) |
19
|
|
|
{ |
20
|
|
|
$typeBadge = sprintf(<<<'html' |
21
|
|
|
<span class="badge badge-%s"> |
22
|
|
|
<i class="fa fa-%s"></i> %s |
23
|
|
|
</span> |
24
|
|
|
html, |
25
|
|
|
$this->resource->type->isCoin() ? 'danger' : 'success', |
|
|
|
|
26
|
|
|
$this->resource->type->isCoin() ? 'coins' : 'money-bill', |
27
|
|
|
$this->resource->type->label |
28
|
|
|
); |
29
|
|
|
|
30
|
|
|
$elements = []; |
31
|
|
|
|
32
|
|
|
if ($request->user()->can('view', $this->resource)) { |
33
|
|
|
$elements[] = view('components.datatables.link-show', [ |
34
|
|
|
'url' => route('admin.denomination.show', $this->resource), |
35
|
|
|
])->render(); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
if ($request->user()->can('update', $this->resource)) { |
39
|
|
|
$elements[] = view('components.datatables.link-edit', [ |
40
|
|
|
'url' => route('admin.denomination.edit', $this->resource), |
41
|
|
|
])->render(); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
if ($request->user()->can('delete', $this->resource)) { |
45
|
|
|
$elements[] = view('components.datatables.link-destroy', [ |
46
|
|
|
'url' => route('admin.denomination.destroy', $this->resource), |
47
|
|
|
])->render(); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
return [ |
51
|
|
|
'checkbox' => view('components.datatables.checkbox', [ |
52
|
|
|
'value' => $this->resource->getKey(), |
53
|
|
|
])->render(), |
54
|
|
|
'name' => $this->resource->name, |
55
|
|
|
'value' => $this->resource->value_rupiah, |
56
|
|
|
'type' => $typeBadge, |
57
|
|
|
'quantity_per_bundle' => $this->resource->quantity_per_bundle . ' ' . trans('bundle'), |
|
|
|
|
58
|
|
|
'action' => view('components.datatables.button-group', compact('elements'))->render(), |
59
|
|
|
]; |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|