add cawangan api

This commit is contained in:
Zakwan Hamdan
2020-10-22 11:25:26 +08:00
parent d566c2e499
commit 94eb988dd5
4 changed files with 87 additions and 0 deletions
+26
View File
@@ -0,0 +1,26 @@
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Cawangan extends Model
{
protected $table = 'arrahn_master_db';
/**
* The attributes that are mass assignable.
*
* @var array
*/
// protected $fillable = [
// ];
/**
* The attributes excluded from the model's JSON form.
*
* @var array
*/
// protected $hidden = [];
}
@@ -0,0 +1,44 @@
<?php
namespace App\Http\Controllers;
use App\Cawangan;
use Illuminate\Http\Request;
class CawanganController extends Controller
{
public function showAllCawangans()
{
return response()->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);
}
}
+13
View File
@@ -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,
],
],
];
+4
View File
@@ -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']);
});