join('ruang_pelayanans', 'pegawais.ruang_pelayanan_id', '=', 'ruang_pelayanans.id');
return DataTables::of($pegawai)
->editColumn('created_at', function ($row) {
return Carbon::parse($row->created_at)->format('d-m-Y H:i');
})
->editColumn('updated_at', function ($row) {
return Carbon::parse($row->updated_at)->format('d-m-Y H:i');
})
->addColumn('action', function ($row) {
return 'Edit
';
})
->rawColumns(['action'])
->make(true);
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
//
$data['title'] = 'TAMBAH PEGAWAI';
$data['ruang_pelayanan'] = Ruang_pelayanan::all();
return view('pegawai.create', $data);
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request)
{
//
$name = $request->name;
$ruang_pelayanan = $request->ruang_pelayanan_id;
try {
DB::beginTransaction();
$insert = Pegawai::create([
'pegawai_name' => $name,
'ruang_pelayanan_id' => $ruang_pelayanan
]);
DB::commit();
$data_return = [
'status' => true,
'data' => null,
'msg' => null
];
return response()->json($data_return, 200);
} catch (Exception $e) {
DB::rollBack();
// Handle the exception or log the error
dd($e);
$data_return = [
'status' => false,
'data' => null,
'msg' => 'something wrong!!'
];
return response()->json($data_return, 500);
}
}
/**
* Display the specified resource.
*/
public function show(string $id)
{
//
}
/**
* Show the form for editing the specified resource.
*/
public function edit(string $id)
{
//
$data['title'] = 'EDIT PEGAWAI';
$data['pegawai'] = Pegawai::findorFail($id);
$data['ruang_pelayanan'] = Ruang_pelayanan::all();
return view('pegawai.edit', $data);
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request)
{
//
$id = $request->id;
$name = $request->name;
$ruang_pelayanan = $request->ruang_pelayanan_id;
$pegawai = Pegawai::findorFail($id);
if (!$pegawai) {
$data_return = [
'status' => false,
'data' => null,
'msg' => 'Data Not Found!'
];
return response()->json($data_return, 404);
}
try {
DB::beginTransaction();
$pegawai->update([
'pegawai_name' => $name,
'ruang_pelayanan_id' => $ruang_pelayanan
]);
DB::commit();
$data_return = [
'status' => true,
'data' => null,
'msg' => null
];
return response()->json($data_return, 200);
} catch (Exception $e) {
//throw $th;
DB::rollBack();
$data_return = [
'status' => false,
'data' => null,
'msg' => 'something wrong!!',
'msg_for_dev' => $e->getMessage()
];
return response()->json($data_return, 500);
}
}
/**
* Remove the specified resource from storage.
*/
public function destroy(Request $request)
{
//
$id = $request->id;
$pegawai = Pegawai::findorFail($id);
if (!$pegawai) {
$data_return = [
'status' => false,
'data' => null,
'msg' => 'Data Not Found!'
];
return response()->json($data_return, 404);
}
try {
DB::beginTransaction();
$pegawai->delete();
DB::commit();
$data_return = [
'status' => true,
'data' => null,
'msg' => null
];
return response()->json($data_return, 200);
} catch (Exception $e) {
//throw $th;
DB::rollBack();
$data_return = [
'status' => false,
'data' => null,
'msg' => 'something wrong!!',
'msg_for_dev' => $e->getMessage()
];
return response()->json($data_return, 500);
}
}
}