Reputation: 19
why do I always get an error The GET method is not supported for route api/addbooking. Supported methods: POST.
even though it already is
Route::post('/addbooking', [BookingController::class, 'store']);
public function store(Request $request): JsonResponse
{
Log::info('Method digunakan:', ['method' => $request->method()]);
Log::info('Data diterima:', $request->all());
// Validasi data yang diterima
$validatedData = $request->validate([
'no_ktp' => 'string|max:255',
'nama' => 'string|max:255',
'alamat' => 'string|max:255',
'no_hp' => 'string|max:15',
'tanggal_sewa' => 'date',
'tanggal_kembali' => 'date|after:tanggal_sewa',
'id_user' => 'string',
'id_mobil' => 'string',
'total_harga' => 'numeric',
'kode_booking' => 'string|max:255|unique:booking',
]);
// Simpan data booking ke database
$booking = Booking::create($validatedData);
return response()->json(['message' => 'Booking berhasil!', 'kode_booking' => $booking->kode_booking], 201);
}
frontend
fetch('http://127.0.0.1:8000/api/addbooking', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(bookingData)
})
Upvotes: 0
Views: 50
Reputation: 11
Use these commands and then try again.
php artisan cache:clear
php artisan route:clear
Upvotes: -1