From 94eb988dd504dc84ed050456a138ae7f62963dfc Mon Sep 17 00:00:00 2001 From: Zakwan Hamdan Date: Thu, 22 Oct 2020 11:25:26 +0800 Subject: [PATCH] add cawangan api --- app/Cawangan.php | 26 ++++++++++++ app/Http/Controllers/CawanganController.php | 44 +++++++++++++++++++++ config/database.php | 13 ++++++ routes/web.php | 4 ++ 4 files changed, 87 insertions(+) create mode 100644 app/Cawangan.php create mode 100644 app/Http/Controllers/CawanganController.php diff --git a/app/Cawangan.php b/app/Cawangan.php new file mode 100644 index 0000000..c17b0b1 --- /dev/null +++ b/app/Cawangan.php @@ -0,0 +1,26 @@ +json(Cawangan::all()); + } + + public function showOneCawangan($code_cawangan) + { + $cawangan = Cawangan::on('mysql7') + ->where('kodcaw','=',$code_cawangan) + ->first(); + return response()->json($cawangan); + } + + public function create(Request $request) + { + $cawangan = Cawangan::create($request->all()); + + return response()->json($cawangan, 201); + } + + public function update($id, Request $request) + { + $cawangan = Cawangan::findOrFail($id); + $cawangan->update($request->all()); + + return response()->json($cawangan, 200); + } + + public function delete($id) + { + Cawangan::findOrFail($id)->delete(); + return response('Deleted Successfully', 200); + } +} \ No newline at end of file diff --git a/config/database.php b/config/database.php index 1d09306..901cf6f 100644 --- a/config/database.php +++ b/config/database.php @@ -82,5 +82,18 @@ return [ 'prefix' => '', 'strict' => false, ], + + 'mysql7' => [ + 'driver' => 'mysql', + 'host' => env('DB_HOST_7'), + 'port' => env('DB_PORT'), + 'database' => env('DB_DATABASE_7'), + 'username' => env('DB_USERNAME_7'), + 'password' => env('DB_PASSWORD_7'), + 'charset' => 'utf8', + 'collation' => 'utf8_unicode_ci', + 'prefix' => '', + 'strict' => false, + ], ], ]; \ No newline at end of file diff --git a/routes/web.php b/routes/web.php index d967e0d..813adb4 100644 --- a/routes/web.php +++ b/routes/web.php @@ -49,4 +49,8 @@ $router->group(['prefix'=>'api'], function () use ($router){ //Harga Emas API $router->get('harga_emas',['uses'=>'HargaEmasController@showAllHargaEmas']); $router->put('harga_emas',['uses'=>'HargaEmasController@update']); + + //Cawangan API + $router->get('cawangan',['uses'=>'CawanganController@showAllCawangans']); + $router->get('cawangan/{code_cawangan}',['uses'=>'CawanganController@showOneCawangan']); }); \ No newline at end of file