Laravel三元表达式失效:会议参与者信息收集设置无法更新数据库
You've already nailed down the root cause here—great catch! The issue boils down to a typo in the radio button's value attribute that's making your backend logic never trigger the 1 case for the all_participants database field. Let's walk through the fixes step by step:
1. Correct the Radio Button Value & Label Attribute
Your second radio button has a typo: all_partcipants (missing an i in "participants"). This means when a user selects "All participants", the form sends all_partcipants instead of the value your backend is checking for (all_participants). Update your form code to fix this, and also correct the for attribute on the label to match the radio button's id (it was incorrectly pointing to exampleRadios1 before):
<form method="post" class="clearfix" action="{{route('questions.update', ['conf_id' => $conf->id])}}" enctype="multipart/form-data"> {{csrf_field()}} <div class="form-group"> <label for="inputName">Collect info</label> <div class="form-check"> <input class="form-check-input" type="radio" name="participants" id="not_all_participants" value="not_all_participants" checked> <label class="form-check-label" for="not_all_participants"> Only for the guy that does the registration </label> </div> <div class="form-check"> <input class="form-check-input" type="radio" name="participants" id="all_participants" value="all_participants"> <label class="form-check-label" for="all_participants"> All participants </label> </div> </div> ... </form>
2. Verify Backend Logic (No Changes Needed After Typo Fix)
Once the radio button's value matches what your backend is checking for, your existing ternary logic will work exactly as intended:
public function update(Request $request, $id){ // dd($request->participants); // Uncomment this line to debug the submitted value $conf = Conference::find($id); $conf->all_participants = ($request->participants == "all_participants" ? 1 : 0); $conf->save(); ... }
If you want to add a little robustness for users who might have cached the old form version, you could temporarily adjust the ternary to check for both the typo'd and correct value, but fixing the form's typo is the permanent solution.
Quick Debug Tip
For future form issues, use dd($request->all()) or dd($request->participants) to inspect exactly what data is being sent from the frontend to the backend—it's a fast, reliable way to spot mismatches like this!
内容的提问来源于stack exchange,提问作者user9289573

