controller(update) :as you can see in the update i'm trying to edit the room reservation(time and date),but onlly one part work the if or the else!
public function update(Request $request, Roomreservation $roomreservation)
{
$request->validate([
'date' => 'required',
'time' => 'required',
]);
$roomreservation = Roomreservation::where('date', request('date'))->where('time', request('time'))->where('code_room', request('code_room'));
if ($roomreservation->exists()) {
return back()->with('erreur', 'The chosen room is already reserved');
}
else {
$roomreservation->update([
"date" => $request->date,
"time" => $request->time,
]);
return back()->with('message_sent', 'room reservation edited successfully!');
}
}
my form
<form method="post" action="{{ route('admin.roomreservations.update', $roomreservation->id) }}">
@csrf
@method('PUT') @method('PUT')
<div>
<div>
<label for="date">Date</label>
<input type="date" min="2022-01-01" max="2022-12-31" name="date" id="date"
value="{{ old('date', $roomreservation->date) }}" />
</div>
<div>
<label for="time">Time</label>
<select name="time" id="time"
value="{{ old('time',$roomreservation->time) }}" >
<option>8H30-10H00</option>
<option>10H00-11H30</option>
<option>11H30-13H00</option>
</select>
</div>
<div>
<button>
Edit
</button>
</div>
</div>
</form>
button update on the index form
<a href="{{ route('admin.roomreservations.edit', $roomreservation->id) }}" >Update</a>
i think something is wrong on the update condition
$roomreservation = Roomreservation::where('date', request('date'))->where('time', request('time'))->where('code_room', request('code_room'));
if ($roomreservation->exists())