Siopas Inventory PETI for ISTW Website
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

94 lines
2.6 KiB

<?php
namespace App\Http\Controllers\API\v1\PetiApi;
use App\Helpers\ResponseFormatter;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
class PetiApiController extends Controller
{
public function index()
{
$petis = \App\Models\Peti::with([
'customer:id,name,code_customer,lot_no,nip,no_hp,tgl_lahir,jenis_kelamin,agama,address',
'tipe_peti:id,type,size_peti,description',
'warehouse:id,name,address',
])->get();
if (!$petis) {
return ResponseFormatter::error([
'message' => 'Data peti tidak ditemukan',
], 'Data Not Found', 404);
}
return ResponseFormatter::success([
'message' => 'Data peti berhasil diambil',
'petis' => $petis,
], 200);
}
public function show($id)
{
$peti = \App\Models\Peti::with([
'customer:id,name,code_customer,lot_no,nip,no_hp,tgl_lahir,jenis_kelamin,agama,address',
'tipe_peti:id,type,size_peti,description',
'warehouse:id,name,address',
])->find($id);
if (!$peti) {
return ResponseFormatter::error([
'message' => 'Data peti tidak ditemukan',
], 'Data Not Found', 404);
}
return ResponseFormatter::success([
'message' => 'Data peti berhasil diambil',
'peti' => $peti,
], 200);
}
public function edit($id)
{
$peti = \App\Models\Peti::with([
'customer:id,name,code_customer,lot_no,nip,no_hp,tgl_lahir,jenis_kelamin,agama,address',
'tipe_peti:id,type,size_peti,description',
'warehouse:id,name,address',
])->find($id);
if (!$peti) {
return ResponseFormatter::error([
'message' => 'Data peti tidak ditemukan',
], 'Data Not Found', 404);
}
return ResponseFormatter::success([
'message' => 'Data peti berhasil diambil',
'petis' => $peti,
], 200);
}
public function update(Request $request, $id)
{
$peti = \App\Models\Peti::find($id);
if (!$peti) {
return ResponseFormatter::error([
'message' => 'Data peti tidak ditemukan',
], 'Data Not Found', 404);
}
// $peti->update($request->all());
$peti->update([
'warehouse_id' => $request->warehouse_id,
'updated_by' => $request->updated_by,
]);
return ResponseFormatter::success([
'message' => 'Data peti berhasil diupdate',
'petis' => $peti,
], 200);
}
}