Skip to content

Commit 8a63657

Browse files
committed
Add relationship to Tindak Lanjut in PelaksanaanTindakLanjut model; update Nova resources to filter months based on triwulan selection
1 parent 02215a3 commit 8a63657

File tree

4 files changed

+27
-6
lines changed

4 files changed

+27
-6
lines changed

app/Models/PelaksanaanTindakLanjut.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,15 @@
33
namespace App\Models;
44

55
use Illuminate\Database\Eloquent\Model;
6+
use Illuminate\Database\Eloquent\Relations\BelongsTo;
67

78
class PelaksanaanTindakLanjut extends Model
89
{
10+
public function tindakLanjut(): BelongsTo
11+
{
12+
return $this->belongsTo(TindakLanjut::class);
13+
}
14+
915
protected $casts = [
1016
'bukti_dukung' => 'array',
1117
];

app/Nova/AnalisisSakip.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public function fields(NovaRequest $request)
7272
->sortable()
7373
->exceptOnForms(),
7474
Select::make('Bulan Pelaksanaan', 'bulan')
75-
->options(Helper::$bulan)
75+
->options(array_slice(Helper::$bulan, 0, now()->month, true))
7676
->displayUsingLabels()
7777
->sortable()
7878
->filterable()

app/Nova/PelaksanaanTindakLanjut.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
class PelaksanaanTindakLanjut extends Resource
1616
{
17+
public static $with = ['tindakLanjut'];
1718
/**
1819
* The model the resource corresponds to.
1920
*
@@ -60,7 +61,21 @@ public function fields(NovaRequest $request)
6061
{
6162
return [
6263
Select::make('Bulan Pelaksanaan', 'bulan')
63-
->options(Helper::$bulan)
64+
->options(function () {
65+
$triwulan = $this->tindakLanjut->triwulan;
66+
switch ($triwulan) {
67+
case 1:
68+
return array_intersect_key(Helper::$bulan, array_flip([4, 5, 6]));
69+
case 2:
70+
return array_intersect_key(Helper::$bulan, array_flip([7, 8, 9]));
71+
case 3:
72+
return array_intersect_key(Helper::$bulan, array_flip([10, 11, 12]));
73+
case 4:
74+
return array_intersect_key(Helper::$bulan, array_flip([1, 2, 3]));
75+
default:
76+
return [];
77+
}
78+
})
6479
->displayUsingLabels()
6580
->sortable()
6681
->filterable()

app/Nova/TindakLanjut.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,10 @@ public function fields(NovaRequest $request)
7272
->exceptOnForms(),
7373
Select::make('Triwulan')
7474
->options([
75-
1 => 'Triwulan I',
76-
2 => 'Triwulan II',
77-
3 => 'Triwulan III',
78-
4 => 'Triwulan IV',
75+
1 => 'Triwulan 1',
76+
2 => 'Triwulan 2',
77+
3 => 'Triwulan 3',
78+
4 => 'Triwulan 4',
7979
])
8080
->displayUsingLabels()
8181
->filterable()

0 commit comments

Comments
 (0)