Files
api_arrahn/app/Http/Controllers/HargaEmasController.php
T
2021-01-03 10:08:02 +08:00

40 lines
1.1 KiB
PHP

<?php
namespace App\Http\Controllers;
use App\HargaEmas;
use Illuminate\Http\Request;
class HargaEmasController extends Controller
{
public function showAllHargaEmas()
{
return response()->json(HargaEmas::on('mysql7')->orderby('recno')->get());
}
public function getOneHargaEmas($karat){
$karat_string = str_replace('-','.',$karat);
$harga_emas = HargaEmas::on('mysql7')->select('harga2')->where('karat','=',$karat_string)->first();
return response()->json($harga_emas);
}
public function update($id, Request $request)
{
$harga_emas = HargaEmas::findOrFail($id);
$harga_emas->update($request->all());
return response()->json($harga_emas, 200);
}
public function showAllHargaEmasMobile(){
$emas = HargaEmas::on('mysql7')->orderby('recno')->get();
$hargaemas = [];
foreach($emas as $index=>$harga){
array_push($hargaemas,['mutu_emas'=>$harga['keterangan'],'karat'=>$harga['karat'],'harga'=>$harga['harga']]);
}
return response()->json($hargaemas);
}
}