editColumn('tanggal_lahir', function ($row) { return Carbon::parse($row->tanggal_lahir)->format('d-m-Y'); }) ->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); } public function get_data_by_nik(Request $request) { $nik = $request->nik; $get_data = Pasien::where('pasien_nik', $nik)->first(); if ($get_data) { $data_return = [ 'status' => true, 'data' => $get_data, 'msg' => null ]; return response()->json($data_return, 200); } else { $data_return = [ 'status' => false, 'data' => null, 'msg' => 'Data Not Found!' ]; return response()->json($data_return, 404); } } /** * Show the form for creating a new resource. */ public function create() { // $data['title'] = 'TAMBAH PASIEN'; return view('pasien.create', $data); } /** * Store a newly created resource in storage. */ public function store(Request $request) { // $nik = $request->nik; $name = $request->name; $tanggal_lahir = $request->tanggal_lahir; $jenis_kelamin = $request->jenis_kelamin; try { DB::beginTransaction(); $insert = Pasien::create([ 'pasien_nik' => $nik, 'pasien_name' => $name, 'tanggal_lahir' => $tanggal_lahir, 'jenis_kelamin' => $jenis_kelamin ]); 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($id) { // $data['title'] = 'EDIT PASIEN'; $data['pasien'] = Pasien::findorFail($id); return view('pasien.edit', $data); } /** * Update the specified resource in storage. */ public function update(Request $request) { // $id = $request->id; $nik = $request->nik; $name = $request->name; $tanggal_lahir = $request->tanggal_lahir; $jenis_kelamin = $request->jenis_kelamin; $pasien = Pasien::findorFail($id); if (!$pasien) { $data_return = [ 'status' => false, 'data' => null, 'msg' => 'Data Not Found!' ]; return response()->json($data_return, 404); } try { DB::beginTransaction(); $pasien->update([ 'pasien_nik' => $nik, 'pasien_name' => $name, 'tanggal_lahir' => $tanggal_lahir, 'jenis_kelamin' => $jenis_kelamin ]); 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; $pasien = Pasien::findorFail($id); if (!$pasien) { $data_return = [ 'status' => false, 'data' => null, 'msg' => 'Data Not Found!' ]; return response()->json($data_return, 404); } try { DB::beginTransaction(); $pasien->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); } } }