add multiple db connection

This commit is contained in:
Zakwan Hamdan
2020-10-26 08:10:39 +08:00
parent 94eb988dd5
commit 356c091be4
2 changed files with 35 additions and 15 deletions
+33 -15
View File
@@ -5,6 +5,7 @@ namespace App\Http\Controllers;
use App\Customer;
use App\Gadai;
use App\Lelong;
use App\Cawangan;
use Illuminate\Http\Request;
class CustomerController extends Controller
@@ -22,12 +23,19 @@ class CustomerController extends Controller
public function showOneCustomerByIC($ic){
$customer = Customer::on('mysql2')
->where('kplama','=',$ic)
->orWhere('kpbaru','=',$ic)
->first();
$cawangan_all = Cawangan::on('mysql7')->get();
$customer_all = [];
foreach($cawangan_all as $index=>$cawangan){
$customer = Customer::on($cawangan['mysql'])
->where('kplama','=',$ic)
->orWhere('kpbaru','=',$ic)
->first();
if($customer != null){
array_push($customer_all,$customer);
}
}
return response()->json($customer);
return response()->json($customer_all);
}
public function showOneCustomerGadai($ic,$status){
@@ -39,18 +47,28 @@ class CustomerController extends Controller
$gadai_status = 'L';
}
if($status == 'belum_tebus' || $status == 'sudah_tebus'){
$gadai = Gadai::on('mysql2')
->where([['sttebus','=',$gadai_status],['nokp','=',$ic]])
->get();
}elseif($status == 'lelong'){
$gadai = Gadai::on('mysql2')
->where([['sttebus','=',$gadai_status],['nokp','=',$ic]])
->rightJoin('lelong', 'gadai.norujukan', '=', 'lelong.norujukan')
->get();
$cawangan_all = Cawangan::on('mysql7')->get();
$gadai_all = [];
foreach($cawangan_all as $index=>$cawangan){
if($status == 'belum_tebus' || $status == 'sudah_tebus'){
$gadai = Gadai::on($cawangan['mysql'])
->where([['sttebus','=',$gadai_status],['nokp','=',$ic]])
->get();
if(sizeof($gadai) != 0){
array_push($gadai_all,$gadai);
}
}elseif($status == 'lelong'){
$gadai = Gadai::on($cawangan['mysql'])
->where([['sttebus','=',$gadai_status],['nokp','=',$ic]])
->rightJoin('lelong', 'gadai.norujukan', '=', 'lelong.norujukan')
->get();
if(sizeof($gadai) != 0){
array_push($gadai_all,$gadai);
}
}
}
return response()->json($gadai);
return response()->json($gadai_all);
}
public function create(Request $request)