81 lines
3.2 KiB
PHP
81 lines
3.2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Models\FileDirectory;
|
|
use App\Models\MasterKategori;
|
|
use App\Models\MasterKlasifikasi;
|
|
use App\Models\SubUnitKerja;
|
|
use App\Models\UnitKerja;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Facades\Storage;
|
|
use Illuminate\Support\Str;
|
|
|
|
class DashboardController extends Controller
|
|
{
|
|
public function index(){
|
|
dd(auth()->user());
|
|
$unitKerja = UnitKerja::where('statusenabled', true)->select('id', 'name')->get();
|
|
$subUnitKerja = SubUnitKerja::where('statusenabled', true)->select('id', 'name')->get();
|
|
$katDok = MasterKategori::where('statusenabled', true)->select('master_kategori_directory_id', 'nama_kategori_directory')->get();
|
|
$klasifikasiDok = MasterKlasifikasi::where('statusenabled', true)->select('master_klasifikasi_directory_id', 'nama_klasifikasi_directory')->get();
|
|
$payload = [
|
|
'title' => 'Dashboard',
|
|
'unitKerja' => $unitKerja,
|
|
'subUnitKerja' => $subUnitKerja,
|
|
'katDok' => $katDok,
|
|
'klasifikasiDok' => $klasifikasiDok,
|
|
];
|
|
return view('dashboard.index', $payload);
|
|
}
|
|
|
|
public function dataUnitKerja(){
|
|
$unitKerja = UnitKerja::where('statusenabled', true)->select('id', 'name')->get();
|
|
$katDok = MasterKategori::where('statusenabled', true)->select('master_kategori_directory_id', 'nama_kategori_directory')->get();
|
|
$data = [
|
|
'unitKerja' => $unitKerja,
|
|
'katDok' => $katDok
|
|
];
|
|
return response()->json([
|
|
'status' => true,
|
|
'data' => $data,
|
|
], 200);
|
|
}
|
|
|
|
public function store(){
|
|
DB::connection('dbDirectory')->beginTransaction();
|
|
try {
|
|
$datas = request()->input('data');
|
|
foreach($datas as $index => $value){
|
|
$file = request()->file("data.$index.file");
|
|
$payload = [
|
|
'master_klasifikasi_directory_id' => $value['klasifikasi'],
|
|
'id_unit_kerja' => request('id_unit_kerja') ?? null,
|
|
'id_sub_unit_kerja' => request('id_sub_unit_kerja') ?? null,
|
|
'master_kategori_directory_id' => request('master_kategori_directory_id') ?? null,
|
|
'pegawai_id_entry' => auth()->user()->id ?? 1,
|
|
'pegawai_nama_entry' => auth()->user()->namalengkap ?? 'tes',
|
|
];
|
|
if($file){
|
|
$imageName = $file->getClientOriginalName();
|
|
Storage::disk('file_directory')->put($imageName, file_get_contents($file));
|
|
$payload['file'] =$imageName;
|
|
}
|
|
FileDirectory::create($payload);
|
|
}
|
|
DB::connection('dbDirectory')->commit();
|
|
return response()->json([
|
|
'status' => true,
|
|
'message' => 'Data berhasil disimpan',
|
|
], 200);
|
|
} catch (\Throwable $th) {
|
|
DB::connection('dbDirectory')->rollBack();
|
|
return response()->json([
|
|
'status' => false,
|
|
'message' => $th->getMessage()
|
|
], 500);
|
|
}
|
|
}
|
|
}
|