I have to develop a reservation system for a hotel. You first have to create a user and than you can make a reservation. There is an option to edit the registered users but that is the part where I'm stuck. I follow a very good tutorial but at the moment I can't figure out my error from his video or the internet or documentation..
I've used the post method to insert new data inside my database but to edit the data and update it, I have to use the put method. But it gives an error "Too few arguments in my function .. 1 passed in and 2 expected".
I am aware I have to cache the routes at every change!!
This is my controller:
public function store(Request $request)
{
$guest = Guest::create
([
'titel' => $request->input('title'),
'voornaam' => $request->input('fname'),
'achternaam' => $request->input('sname'),
'adres' => $request->input('address'),
'postcode' => $request->input('zipcode'),
'stad' => $request->input('city'),
'provincie' => $request->input('provincie'),
'email' => $request->input('email')
]);
return redirect('./clients.html');
}
public function edit($id)
{
$guest = Guest::find($id);
return view('edit')->with('guest', $guest);
}
public function update(Request $request, $id)
{
$guest = Guest::where('id', $id)
->update([
'titel' => $request->input('title'),
'voornaam' => $request->input('fname'),
'achternaam' => $request->input('sname'),
'adres' => $request->input('address'),
'postcode' => $request->input('zipcode'),
'stad' => $request->input('city'),
'provincie' => $request->input('provincie'),
'email' => $request->input('email')
]);
}
These are my routes:
Route::get('/', [PagesController::class, 'home']);
Route::get('/home.html', [PagesController::class, 'home']);
Route::get('/clients.html', [GuestsController::class, 'saveGuests']);
Route::post('/clients.html', [GuestsController::class, 'store']);
Route::put('/clients.html', [GuestsController::class, 'update']);
Route::get('/reservations.html', [PagesController::class, 'reservations']);
Route::get('/clients_new.html', [GuestsController::class, 'newclients']);
Route::get('/clients/{id}/edit.html', [GuestsController::class, 'edit']);
Route::get('/reservations_new.html', [PagesController::class, 'newReservations']);
And the file I have make the changes is (using the post method at first but inserted a put method):
<form action="/clients.html" method="POST" class="w-3/12 m-auto flex flex-col justify-evenly items-center text-xl">
@csrf
@method('PUT')
<div class="medium-6 columns py-4 text-3xl w-full flex flex-row items-center justify-between">
<label class="font-semibold">Titel</label>
<select name="title" class="w-22 border-solid border-2 border-grey-200 rounded-lg bg-gray-100 p-2" value="{{ $guest->titel }}">
<option value="Mr." selected="selected">Mr.</option>
<option value="Ms.">Mw.</option>
<option value="Mrs.">Juf.</option>
<option value="Dr.">Dr.</option>
</select>
</div>
<div class="medium-6 columns m-auto py-4 text-3xl w-full flex flex-row items-center justify-between">
<label class="font-semibold">Voornaam</label>
<input name="fname" type="text" class="border-solid border-2 border-grey-200 rounded-lg bg-gray-100 p-2 " value="{{ $guest->voornaam }}">
</div>
<div class="medium-6 columns m-auto py-4 text-3xl w-full flex flex-row items-center justify-between">
<label class="font-semibold">Achternaam</label>
<input name="sname" type="text" class="border-solid border-2 border-grey-200 rounded-lg bg-gray-100 p-2" value="{{ $guest->achternaam }}">
</div>