Add backend operation to use with MyKad reader feature

This commit is contained in:
afiq.hamzah
2023-03-06 10:33:22 +08:00
parent a272171ebb
commit 812191032c
5 changed files with 50 additions and 16 deletions
+23 -5
View File
@@ -7,17 +7,35 @@ use Illuminate\Http\Request;
class PoskodController extends Controller
{
public function showAllPoskod(){
public function showAllPoskod()
{
$poskod = Poskod::on('mysql7')->get();
return response()->json($poskod);
}
public function showOnePoskod($poskod)
{
$poskod = Poskod::on('mysql7')
->where('poskod','=',$poskod)
->first();
->where('poskod', '=', $poskod)
->first();
return response()->json($poskod);
}
}
public function store(Request $request)
{
if (Poskod::where('poskod', $request->poskod)->exists()) {
return response()->json('Poskod creation forbidden, already exist', 403);
}
$created_poskod = Poskod::create([
'poskod' => $request->poskod,
'koddaerah' => $request->koddaerah,
'kodnegeri' => $request->kodnegeri,
]);
return response()->json($created_poskod, 200);
}
}