Skip to content

Instantly share code, notes, and snippets.

@ahmadshobirin
Created November 6, 2017 03:59
Show Gist options
  • Save ahmadshobirin/cb90bd7008964dfc1d9467b9afb368bf to your computer and use it in GitHub Desktop.
Save ahmadshobirin/cb90bd7008964dfc1d9467b9afb368bf to your computer and use it in GitHub Desktop.
merge array with concate select to json
$data = [];
//ambil alamat asli customer
$customer = DB::table('m_customer')->select(DB::raw("CONCAT(m_customer.main_address,' - ',m_kelurahan_desa.name,' - ',m_kecamatan.name,' - ',m_kota_kab.type,' ',m_kota_kab.name) as address"))
->join('m_kelurahan_desa','m_kelurahan_desa.id','=','m_customer.main_kelurahan')
->join('m_kecamatan','m_kecamatan.id','=','m_kelurahan_desa.kecamatan')
->join('m_kota_kab','m_kota_kab.id','=','m_kecamatan.kota_kab')
->where('m_customer.id',$customerID)
->get();
//mencari alamat lainnya customer di m_alamat_customer
$otherAddress = DB::table('m_alamat_customer')->select(DB::raw("CONCAT(m_alamat_customer.address,' - ',m_kelurahan_desa.name,' - ',m_kecamatan.name,' - ',m_kota_kab.type,' ',m_kota_kab.name) as address"))
->join('m_kelurahan_desa','m_kelurahan_desa.id','=','m_alamat_customer.kelurahan')
->join('m_kecamatan','m_kecamatan.id','=','m_kelurahan_desa.kecamatan')
->join('m_kota_kab','m_kota_kab.id','=','m_kecamatan.kota_kab')
->where('m_alamat_customer.customer',$customerID)
->get();
//merge array
$data = array_merge($customer->toArray(),$otherAddress->toArray());
return Response::json($data);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment