Merge branch 'main' of https://git.probindo.com/Probindo/database-pertani-web
This commit is contained in:
@@ -10,6 +10,7 @@ use Illuminate\Http\JsonResponse;
|
|||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
use Illuminate\Support\Facades\Validator;
|
use Illuminate\Support\Facades\Validator;
|
||||||
use Illuminate\Validation\Rule;
|
use Illuminate\Validation\Rule;
|
||||||
|
use Illuminate\Http\RedirectResponse;
|
||||||
|
|
||||||
use App\Models\Ekosistem\TabelBasisData;
|
use App\Models\Ekosistem\TabelBasisData;
|
||||||
use App\Models\Ekosistem\FormBasisData;
|
use App\Models\Ekosistem\FormBasisData;
|
||||||
|
|||||||
@@ -21,6 +21,13 @@ use App\Models\Core\Program;
|
|||||||
|
|
||||||
class ValueBasisDataController extends Controller
|
class ValueBasisDataController extends Controller
|
||||||
{
|
{
|
||||||
|
private $tableModelClassMap = [
|
||||||
|
'master_provinsi' => \App\Models\Wilayah\Provinsi::class,
|
||||||
|
'master_kabupaten_kota' => \App\Models\Wilayah\KabupatenKota::class,
|
||||||
|
'master_kecamatan' => \App\Models\Wilayah\Kecamatan::class,
|
||||||
|
'master_desa_kelurahan' => \App\Models\Wilayah\DesaKelurahan::class,
|
||||||
|
];
|
||||||
|
|
||||||
public function index(Request $request, string $tabelId): View
|
public function index(Request $request, string $tabelId): View
|
||||||
{
|
{
|
||||||
if (!Gate::any(['super_admin', 'admin', 'fasilitator'])) {
|
if (!Gate::any(['super_admin', 'admin', 'fasilitator'])) {
|
||||||
@@ -198,7 +205,12 @@ class ValueBasisDataController extends Controller
|
|||||||
if ($k->tipe == 'foreign_key') {
|
if ($k->tipe == 'foreign_key') {
|
||||||
$relasi['kolom_id'] = $k->id;
|
$relasi['kolom_id'] = $k->id;
|
||||||
try {
|
try {
|
||||||
|
$modelClass = $this->tableModelClassMap[$k->relasi_tabel] ?? null;
|
||||||
|
if ($modelClass) {
|
||||||
|
$options_kolom = $modelClass::select($k->relasi_kolom_label . ' as label', $k->relasi_kolom_id . ' as value')->whereNull('deleted_at');
|
||||||
|
} else {
|
||||||
$options_kolom = DB::table($k->relasi_tabel)->selectRaw($k->relasi_kolom_label . ' as label, ' . $k->relasi_kolom_id . ' as value')->whereNull('deleted_at');
|
$options_kolom = DB::table($k->relasi_tabel)->selectRaw($k->relasi_kolom_label . ' as label, ' . $k->relasi_kolom_id . ' as value')->whereNull('deleted_at');
|
||||||
|
}
|
||||||
$relasi['options'] = $options_kolom->get();
|
$relasi['options'] = $options_kolom->get();
|
||||||
$relasi['sql'] = $options_kolom->toSql();
|
$relasi['sql'] = $options_kolom->toSql();
|
||||||
} catch (\Throwable $th) {
|
} catch (\Throwable $th) {
|
||||||
@@ -281,9 +293,6 @@ class ValueBasisDataController extends Controller
|
|||||||
return redirect()->route('tabel.data.index', [$tabelId, 'program_id' => $program->id])->with('success', 'Data berhasil ditambahkan.');
|
return redirect()->route('tabel.data.index', [$tabelId, 'program_id' => $program->id])->with('success', 'Data berhasil ditambahkan.');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Display the specified resource.
|
|
||||||
*/
|
|
||||||
public function show(Request $request, string $tabelId, string $id): View
|
public function show(Request $request, string $tabelId, string $id): View
|
||||||
{
|
{
|
||||||
if (!Gate::any(['super_admin', 'admin'])) {
|
if (!Gate::any(['super_admin', 'admin'])) {
|
||||||
@@ -329,7 +338,9 @@ class ValueBasisDataController extends Controller
|
|||||||
foreach ($values as $v) {
|
foreach ($values as $v) {
|
||||||
$k = $kolom->where('id', $v->kolom_id)->first();
|
$k = $kolom->where('id', $v->kolom_id)->first();
|
||||||
if ($k->tipe == 'foreign_key') {
|
if ($k->tipe == 'foreign_key') {
|
||||||
$v->value_relasi_label = DB::table($k->relasi_tabel)->where($k->relasi_kolom_id, $v->value_relasi)->value($k->relasi_kolom_label);
|
$v->value_relasi_label = DB::table($k->relasi_tabel)
|
||||||
|
->where($k->relasi_kolom_id, $v->value_relasi)
|
||||||
|
->value($k->relasi_kolom_label);
|
||||||
} else if ($k->tipe == 'enum') {
|
} else if ($k->tipe == 'enum') {
|
||||||
$opsi = collect($k->enum_opsi);
|
$opsi = collect($k->enum_opsi);
|
||||||
$found = $opsi->first(function ($item) use ($v) {
|
$found = $opsi->first(function ($item) use ($v) {
|
||||||
|
|||||||
Reference in New Issue
Block a user