sibanu_web/app/Http/Controllers/API/BarangController.php
2022-08-20 13:21:23 +07:00

79 lines
2.0 KiB
PHP

<?php
namespace App\Http\Controllers\API;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Validator;
use App\Models\Barang;
use App\Models\JenisBarang;
use App\Http\Resources\BarangResource;
class BarangController extends Controller
{
public function index()
{
$data = Barang::join('tbl_satuan','tbl_satuan.id','=','tbl_barang.satuan_id')
->join('tbl_jenis_barang','tbl_jenis_barang.id','=','tbl_barang.jenis_barang_id')
->get(['tbl_barang.*','tbl_satuan.nama_satuan','tbl_jenis_barang.nama_jenis']);
return response()->json(['data'=>BarangResource::collection($data), 'msg'=>'List All data barang']);
}
public function show($id)
{
$data = Barang::where('id',$id)->get();
foreach($data as $i){
$nama_barang = $i->nama_barang;
}
// dd($data);
return response()->json(['data'=>BarangResource::collection($data), 'msg'=>'Detail Barang '.$nama_barang]);
}
public function detail_barang(Request $request)
{
// dd($request->all());
$id_barang = $request->id_barang;
$data = Barang::where('id',$id_barang)->get();
foreach($data as $i){
$nama_barang = $i->nama_barang;
}
// dd($data);
return response()->json(['data'=>BarangResource::collection($data), 'msg'=>'Detail Barang '.$nama_barang]);
}
public function destroy($id)
{
$data = Barang::where('id',$id)->delete();
if($data){
return response()->json(['data'=>'', 'msg'=>'Data Barang Berhasil di hapus ']);
}else{
return response()->json(['data'=>'', 'msg'=>'Data Barang Gagal di hapus ']);
}
}
public function store(Request $request)
{
}
public function jenis_barang()
{
$data = JenisBarang::all();
return response()->json(['data'=>BarangResource::collection($data), 'msg'=>'List Data Jenis Barang']);
}
}