87 lines
2.5 KiB
PHP
87 lines
2.5 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Admin;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Interfaces\MsPasienInterface;
|
|
use Illuminate\Http\Request;
|
|
|
|
class MsPasienController extends Controller
|
|
{
|
|
private $msPasien;
|
|
|
|
public function __construct(MsPasienInterface $msPasien)
|
|
{
|
|
$this->msPasien = $msPasien;
|
|
}
|
|
|
|
public function index(Request $request)
|
|
{
|
|
if ($request->ajax()) {
|
|
return DataTables()->of($this->msPasien->getAll())
|
|
->addIndexColumn()
|
|
->addColumn('mr_pasien', function ($data) {
|
|
return $data->mr_pasien;
|
|
})
|
|
->addColumn('nama_pasien', function ($data) {
|
|
return $data->nama_pasien;
|
|
})
|
|
->addColumn('tanggal_lahir', function ($data) {
|
|
return $data->tanggal_lahir;
|
|
})
|
|
->addColumn('jenis_kelamin', function ($data) {
|
|
return $data->jenis_kelamin;
|
|
})
|
|
->addColumn('action', function ($data) {
|
|
return view('admin.ms_pasien.column.action', compact('data'));
|
|
})
|
|
->make(true);
|
|
}
|
|
|
|
return view('admin.ms_pasien.index');
|
|
}
|
|
|
|
public function create()
|
|
{
|
|
return view('admin.ms_pasien.create');
|
|
}
|
|
|
|
public function store(Request $request)
|
|
{
|
|
$request->validate([
|
|
'nama_pasien' => 'required|string|max:100',
|
|
'tanggal_lahir' => 'required|date',
|
|
'jenis_kelamin' => 'required|string|max:10',
|
|
]);
|
|
|
|
$this->msPasien->store($request->all());
|
|
|
|
return redirect()->route('admin.ms_pasien.index')->with('success', 'Data pasien berhasil ditambahkan.');
|
|
}
|
|
|
|
public function edit($id)
|
|
{
|
|
$pasien = $this->msPasien->getById($id);
|
|
return view('admin.ms_pasien.edit', compact('pasien'));
|
|
}
|
|
|
|
public function update(Request $request, $id)
|
|
{
|
|
$request->validate([
|
|
'nama_pasien' => 'required|string|max:100',
|
|
'tanggal_lahir' => 'required|date',
|
|
'jenis_kelamin' => 'required|string|max:10',
|
|
]);
|
|
|
|
$this->msPasien->update($id, $request->all());
|
|
|
|
return redirect()->route('admin.ms_pasien.index')->with('success', 'Data pasien berhasil diperbarui.');
|
|
}
|
|
|
|
public function destroy($id)
|
|
{
|
|
$this->msPasien->delete($id);
|
|
return response()->json(['success' => 'Data pasien berhasil dihapus.']);
|
|
}
|
|
}
|