안녕하세요 저는 모든 값이 통과하는지 확인할 때이 선택 확인란이 있습니다! 이제 내 문제는 데이터베이스에 저장할 때 하나의 값만 저장된다는 것입니다. 이것은 내 HTML입니다
<p>Sunday</p>
<input type="checkbox" name="select-all-sunday" id="select-all-sunday" onclick="toggle(this);"> Check All
<br>
<input type="checkbox" name="checkbox-sunday[]" id="checkbox-1" value="00:00"> 00:00 <br>
<input type="checkbox" name="checkbox-sunday[]" id="checkbox-2" value="1:00"> 1:00 <br>
<input type="checkbox" name="checkbox-sunday[]" id="checkbox-3" value="2:00"> 2:00 <br>
<input type="checkbox" name="checkbox-sunday[]" id="checkbox-4" value="3:00"> 3:00 <br>
<input type="checkbox" name="checkbox-sunday[]" id="checkbox-5" value="4:00"> 4:00 <br>
<input type="checkbox" name="checkbox-sunday[]" id="checkbox-6" value="5:00"> 5:00 <br>
<input type="checkbox" name="checkbox-sunday[]" id="checkbox-7" value="6:00"> 6:00 <br>
<input type="checkbox" name="checkbox-sunday[]" id="checkbox-8" value="7:00"> 7:00 <br>
<input type="checkbox" name="checkbox-sunday[]" id="checkbox-9" value="8:00"> 8:00 <br>
<input type="checkbox" name="checkbox-sunday[]" id="checkbox-10" value="9:00"> 9:00 <br>
<input type="checkbox" name="checkbox-sunday[]" id="checkbox-11" value="10:00"> 10:00 <br>
<input type="checkbox" name="checkbox-sunday[]" id="checkbox-12" value="11:00"> 11:00 <br>
<input type="checkbox" name="checkbox-sunday[]" id="checkbox-13" value="12:00"> 12:00 <br>
<input type="checkbox" name="checkbox-sunday[]" id="checkbox-14" value="13:00"> 13:00 <br>
<input type="checkbox" name="checkbox-sunday[]" id="checkbox-15" value="14:00"> 14:00 <br>
<input type="checkbox" name="checkbox-sunday[]" id="checkbox-16" value="15:00"> 15:00 <br>
<input type="checkbox" name="checkbox-sunday[]" id="checkbox-17" value="16:00"> 16:00 <br>
<input type="checkbox" name="checkbox-sunday[]" id="checkbox-18" value="17:00"> 17:00 <br>
<input type="checkbox" name="checkbox-sunday[]" id="checkbox-19" value="18:00"> 18:00 <br>
<input type="checkbox" name="checkbox-sunday[]" id="checkbox-20" value="19:00"> 19:00 <br>
<input type="checkbox" name="checkbox-sunday[]" id="checkbox-21" value="20:00"> 20:00 <br>
<input type="checkbox" name="checkbox-sunday[]" id="checkbox-22" value="21:00"> 21:00 <br>
<input type="checkbox" name="checkbox-sunday[]" id="checkbox-23" value="22:00"> 22:00 <br>
<input type="checkbox" name="checkbox-sunday[]" id="checkbox-24" value="23:00"> 23:00 <br>
이것은 이제 내 컨트롤러입니다
$sundays = $request->input('checkbox-sunday');
foreach($sundays as $sunday){
echo $sunday.",";
}
이제 echo $ sunday는 양식 표시에서 전달되는 값이 올바르게 표시됩니다. 이제 데이터베이스에 저장할 때 하나의 값만 저장됩니다.
아래는 데이터베이스에 저장할 때의 코드입니다.
$sundays = $request->input('checkbox-sunday');
foreach($sundays as $sunday){
echo $sunday.",";
$postRoom = PostRoom::find($id);
$postRoom->description = $request->get('description');
$postRoom->checkin_date = $request->get('bookingDate');
$postRoom->checkin_time = $request->get('checkinTime');
$postRoom->room_price = $request->get('roomPrice');
$postRoom->day_sunday = $sunday;
$postRoom->your_neighbourhood = $request->get('yourNeighbourhood');
$postRoom->save();
return redirect('add-your-listing/next-step-3/'.$postRoom->id);
}
이것을 저장하는 가장 좋은 방법은 무엇입니까?. 누군가 나를 도울 수 있습니까? TIA.
보통 당신은 당신의 루프에서 보내고 당신은 매번 id를 찾고 현재의 give 루프를 저장하여 그것을 분쇄합니다. 가장 좋은 것은 테이블을 만들고이 테이블을이 필드에 보내는 것입니다 (내 영어에 대해 죄송합니다)
나는 이것을 시도한다.
$sundays = $request->input('checkbox-sunday');
$sundaysArray = array();
foreach($sundays as $sunday){
$sundaysArray[] = $sunday;
}
$postRoom = PostRoom::find($id);
$postRoom->description = $request->get('description');
$postRoom->checkin_date = $request->get('bookingDate');
$postRoom->checkin_time = $request->get('checkinTime');
$postRoom->room_price = $request->get('roomPrice');
$postRoom->day_sunday = json_encode($sundaysArray);
$postRoom->your_neighbourhood = $request->get('yourNeighbourhood');
$postRoom->save();
return redirect('add-your-listing/next-step-3/'.$postRoom->id);
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다