CRUD Doctor Hospital
This commit is contained in:
@@ -47,7 +47,44 @@ class OrganizationController extends Controller
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
//
|
||||
$organization = [
|
||||
'code' => $request->code,
|
||||
'name' => $request->name,
|
||||
'type' => 'hospital',
|
||||
'status' => $request->active == 1 ? 'active' : 'inactive',
|
||||
'description' => $request->description,
|
||||
];
|
||||
|
||||
$create_organization = Organization::create($organization);
|
||||
|
||||
if ($request->phone != null) {
|
||||
$create_organization->metas()->create([
|
||||
'system' => 'default',
|
||||
'type' => 'phone',
|
||||
'value' => $request->phone,
|
||||
]);
|
||||
}
|
||||
|
||||
$address = $create_organization->addresses()->create([
|
||||
'use' => 'both',
|
||||
'type' => 'physical',
|
||||
'text' => $request->address,
|
||||
'province_id' => $request->province_id,
|
||||
'city_id' => $request->city_id,
|
||||
'district_id' => $request->district_id,
|
||||
'village_id' => $request->village_id,
|
||||
'postal_code' => $request->postal_code,
|
||||
'lat' => $request->lat,
|
||||
'lng' => $request->lng,
|
||||
]);
|
||||
|
||||
$create_organization->main_address_id = $address->id;
|
||||
$create_organization->save();
|
||||
|
||||
return response()->json([
|
||||
'message' => 'Data berhasil disimpan',
|
||||
'data' => new OrganizationResource($create_organization)
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -57,7 +94,7 @@ class OrganizationController extends Controller
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
return view('internal::show');
|
||||
return response()->json(OrganizationResource::make(Organization::find($id)));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -67,7 +104,7 @@ class OrganizationController extends Controller
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
return view('internal::edit');
|
||||
return response()->json(OrganizationResource::make(Organization::find($id)));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -78,7 +115,46 @@ class OrganizationController extends Controller
|
||||
*/
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
//
|
||||
$update_organization = Organization::find($id);
|
||||
|
||||
$update_organization->update([
|
||||
'code' => $request->code,
|
||||
'name' => $request->name,
|
||||
'type' => 'hospital',
|
||||
'status' => $request->active == 1 ? 'active' : 'inactive',
|
||||
'description' => $request->description,
|
||||
]);
|
||||
|
||||
if ($request->phone != null) {
|
||||
$update_organization->metas()->updateOrCreate([
|
||||
'system' => 'default',
|
||||
'type' => 'phone',
|
||||
], [
|
||||
'system' => 'default',
|
||||
'type' => 'phone',
|
||||
'value' => $request->phone,
|
||||
]);
|
||||
}
|
||||
|
||||
$update_organization->addresses()->updateOrCreate([
|
||||
'id' => $update_organization->main_address_id
|
||||
], [
|
||||
'use' => 'both',
|
||||
'type' => 'physical',
|
||||
'text' => $request->address,
|
||||
'province_id' => $request->province_id,
|
||||
'city_id' => $request->city_id,
|
||||
'district_id' => $request->district_id,
|
||||
'village_id' => $request->village_id,
|
||||
'postal_code' => $request->postal_code,
|
||||
'lat' => $request->lat,
|
||||
'lng' => $request->lng,
|
||||
]);
|
||||
|
||||
return response()->json([
|
||||
'message' => 'Data berhasil diubah',
|
||||
'data' => new OrganizationResource($update_organization)
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -88,6 +164,12 @@ class OrganizationController extends Controller
|
||||
*/
|
||||
public function destroy($id)
|
||||
{
|
||||
//
|
||||
$delete_organization = Organization::find($id);
|
||||
$delete_organization->addresses()->delete();
|
||||
$delete_organization->delete();
|
||||
return response()->json([
|
||||
'message' => 'Data berhasil dihapus',
|
||||
'data' => new OrganizationResource($delete_organization)
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user