Previously my create data module was running and there was no error, but when I added a new module, my store function couldn’t be used and I don’t know what the cause was because there was no error message in my console
here is my controller
[
'user' => [
'name' => Auth::user()->name,
'email' => Auth::user()->email,
],
],
'posts' => ['data' => $postRumahsakits],
]);
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
return Inertia::render('Rumahsakit/post');
}
/**
* Store a newly created resource in storage.
*/
public function store(StoreRumahsakitRequest $request)
{
$data = $request->validated();
if ($request->hasFile('image')) {
$imagePath = $request->file('image')->store('rumahsakit_fotos', 'public');
$data['image'] = $imagePath;
} else {
$data['image'] = null;
}
Rumahsakit::create($data);
return Redirect::route('rumahsakit.index');
}
/**
* Display the specified resource.
*/
public function show(Rumahsakit $Rumahsakit)
{
//
}
/**
* Show the form for editing the specified resource.
*/
public function edit(Rumahsakit $Rumahsakit)
{
return Inertia::render('Rumahsakit/edit', [
'post' => [
'id' => $rumahsakit->id,
'nama' => $rumahsakit->nama,
'alamat' => $rumahsakit->alamat,
'telepon' => $rumahsakit->telepon,
'nomorwa' => $rumahsakit->nomorwa,
'maps' => $rumahsakit->maps,
'transportasi' => $rumahsakit->transportasi,
'kelas' => $rumahsakit->kelas,
'ketersediaan' => $rumahsakit->ketersediaan,
'image' => $rumahsakit->image,
]
]);
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request, $id)
{
$rumahsakit = Rumahsakit::findOrFail($id);
$validated = $request->validate([
'nama' => 'nullable|string|max:255',
'alamat' => 'nullable|string',
'telepon' => 'nullable|string',
'nomorwa' => 'nullable|string',
'maps' => 'nullable|string',
'transportasi' => 'nullable|string',
'kelas' => 'nullable|string',
'ketersediaan' => 'boolean',
'image' => 'nullable|image|max:2048',
]);
if ($request->hasFile('image')) {
$path = $request->file('image')->store('rumahsakit_image', 'public');
$validated['image'] = $path;
}
$rumahsakit->update($validated);
return redirect()->route('rumahsakit.index')->with('success', 'Data berhasil diperbarui.');
}
/**
* Remove the specified resource from storage.
*/
public function destroy(Rumahsakit $rumahsakit)
{
$rumahsakit->delete();
return Redirect::route('rumahsakit.index');
}
}
this is for my StoreRumahsakitRequest
|string>
*/
public function rules(): array
{
return [
'nama' => 'required|string|max:255',
'alamat' => 'required|string',
'telepon' => 'required|string|max:255',
'nomorwa' => 'required|string|max:255',
'maps' => 'required|string',
'transportasi' => 'required|string',
'kelas' => 'required|string|max:255',
'ketersediaan' => 'required|boolean',
'foto' => 'required|image|mimes:jpeg,png,jpg,gif|max:2048',
];
}
}
this is for my model
this is for my Rumahsakit/post.tsx
import React from "react";
import { Link, useForm } from "@inertiajs/react";
import AuthenticatedLayout from "@/Layouts/AuthenticatedLayout";
import { PageProps } from "@/types";
// Define the types for form data and errors
interface FormData {
nama: string;
alamat: string;
telepon: string;
nomorwa: string;
maps: string;
transportasi: string;
kelas: string;
image: File | null;
ketersediaan: boolean;
}
const Create = ({ auth }: PageProps) => {
const { data, setData, errors, post } = useForm({
nama: "",
alamat: "",
telepon: "",
nomorwa: "",
maps: "",
transportasi: "",
kelas: "",
image: null,
ketersediaan: false,
});
const [isSubmitting, setIsSubmitting] = React.useState(false);
// Handle form submission
function handleSubmit(e: React.FormEvent) {
e.preventDefault();
setIsSubmitting(true);
const formData = new FormData();
formData.append("nama", data.nama);
formData.append("alamat", data.alamat);
formData.append("telepon", data.telepon);
formData.append("nomorwa", data.nomorwa);
formData.append("maps", data.maps);
formData.append("transportasi", data.transportasi);
formData.append("kelas", data.kelas);
formData.append("ketersediaan", data.ketersediaan ? "1" : "0");
if (data.image) {
formData.append("image", data.image);
}
post(route("rumahsakit.store"), {
data: formData,
onFinish: () => setIsSubmitting(false),
});
}
return (
Dashboard
}
>
);
};
export default Create;
and this is for my route
Route::resource('rumahsakit', RumahsakitController::class);
I’ve tried to use parameters in my route and there is no effect on my code