78 lines
1.7 KiB
PHP
78 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Models\Pasien;
|
|
use App\Http\Requests\StorePasienRequest;
|
|
use App\Http\Requests\UpdatePasienRequest;
|
|
|
|
class PasienController extends Controller
|
|
{
|
|
/**
|
|
* Display a listing of the resource.
|
|
*/
|
|
public function index()
|
|
{
|
|
return Pasien::all();
|
|
}
|
|
|
|
/**
|
|
* Show the form for creating a new resource.
|
|
*/
|
|
public function create()
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Store a newly created resource in storage.
|
|
*/
|
|
public function store(StorePasienRequest $request)
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Display the specified resource.
|
|
*/
|
|
public function show(Pasien $pasien)
|
|
{
|
|
$pasien = Pasien::findOrFail($pasien->id);
|
|
return response()->json($pasien);
|
|
}
|
|
|
|
/**
|
|
* Show the form for editing the specified resource.
|
|
*/
|
|
public function edit(Pasien $pasien) {
|
|
return view('pasien.edit', compact('pasien'));
|
|
}
|
|
|
|
/**
|
|
* Update the specified resource in storage.
|
|
*/
|
|
public function update(UpdatePasienRequest $request, Pasien $pasien)
|
|
{
|
|
$validated = $request->validate([
|
|
'nik' => 'required|max:16|unique:pasiens,nik,'.$pasien->id,
|
|
'nama_pasien' => 'sometimes|max:100',
|
|
'jenis_kelamin' => 'sometimes|in:Laki-Laki,Perempuan',
|
|
'tanggal_lahir' => 'sometimes|date',
|
|
'nomor_telepon' => 'nullable|max:15|string',
|
|
]);
|
|
|
|
$pasien->update($validated);
|
|
}
|
|
|
|
/**
|
|
* Remove the specified resource from storage.
|
|
*/
|
|
public function destroy(Pasien $pasien)
|
|
{
|
|
$pasien = Pasien::findOrFail($pasien->id);
|
|
$pasien->delete();
|
|
|
|
return response()->json(['message' => 'Pasien berhasil dihapus']);
|
|
}
|
|
}
|