Php 如果复选框位于foreach循环(laravel)中,如何存储复选框值

Php 如果复选框位于foreach循环(laravel)中,如何存储复选框值,php,laravel,Php,Laravel,我有问题列表,所有问题都打印在foreach循环中。我想使用复选框在数据库中存储一些问题id @foreach ($allquestion as $indexKey => $all ) <tr> <th>{{$indexKey+1}}</th> <th>{{substr($all->question,0,20)}} {{ strlen($all->question

我有问题列表,所有问题都打印在foreach循环中。我想使用复选框在数据库中存储一些问题id

@foreach ($allquestion as $indexKey => $all )
          <tr>
            <th>{{$indexKey+1}}</th>
            <th>{{substr($all->question,0,20)}} {{ strlen($all->question)>20 
             ? "..." : ""}}</th>
            <td>{{$all->option1}}</td>
            <td>{{$all->option2}}</td>
            <td>{{$all->option3}}</td>
            <td>{{$all->option4}}</td>
            <td>{{$all->answer}}</td>




            <td>
               <div class="form-check">
                 <input class="form-check-input big-checkbox" 
            name="present[]" type="checkbox" value="{{$all->id}}"   
          id="defaultCheck1">
              </div>
           </td>

          </tr>  @endforeach
@foreach($allquestion作为$indexKey=>$all)
{{$indexKey+1}
{{substr($all->问题,0,20)}{{{strlen($all->问题)>20
? "..." : ""}}
{{$all->option1}
{{$all->option2}
{{$all->option3}
{{$all->option4}
{{$all->answer}
@endforeach
我不知道我把提交按钮放在哪里,也不知道如何从复选框中获取值到控制器中以保存数据

已更新

{!! Form::open(array('route' => 'addq', 'data-parsley-validate' => '', 
'files' => true,'method'=>'post')) !!}
 @foreach ($allquestion as $indexKey => $all )
          <tr>
            <th>{{$indexKey+1}}</th>
            <th>{{substr($all->question,0,20)}} {{ strlen($all->question)>20 ? "..." : ""}}</th>
            <td>{{$all->option1}}</td>
            <td>{{$all->option2}}</td>
            <td>{{$all->option3}}</td>
            <td>{{$all->option4}}</td>
            <td>{{$all->answer}}</td>




            <td>
               <div class="form-check">
           <input type="checkbox" class="form-check-input big-checkbox"  
 name="checked[]" value="{{ $all->id }}">
              </div>
           </td>
          </tr>

      @endforeach
    {{Form::submit('Create Test',['class'=>'btn btn-primary'])}}
    {!! Form::close() !!}
{!!Form::open(数组('route'=>'addq','data parsley validate'=>'',
'files'=>true,'method'=>post'))
@foreach($allquestion作为$indexKey=>$all)
{{$indexKey+1}
{{substr($all->question,0,20)}{{{strlen($all->question)>20?“:”}
{{$all->option1}
{{$all->option2}
{{$all->option3}
{{$all->option4}
{{$all->answer}
@endforeach
{{Form::submit('Create Test',['class'=>'btn-btn-primary'])}
{!!Form::close()!!}

当我按下这样的按钮时,无需执行任何操作。

与我为我的一个项目实现的功能相同,并且工作正常,请检查以下代码。我想这对你会有用的

HTML:

<input type="checkbox" name="checked[]" value="{{ $employee->id }}">
public function store(Request $request)
 {
   foreach ($request->employee_id as $key => $val) 
    {
     $payrolls = new Payroll;
      if (in_array($val, $request->checked))
       {
         $payrolls->basic = $request->basic[$key];
         $payrolls->employee_id = $val;
         $payrolls->save();
       }
    }
return redirect('/');
 }
$present = $request->get('present');
dd($present);
你应该试试这个

刀片文件

<form action="Your route">
@foreach ($allquestion as $indexKey => $all )
         <tr>
           <th>{{$indexKey+1}}</th>
           <th>{{substr($all->question,0,20)}} {{ strlen($all->question)>20
            ? "..." : ""}}</th>
           <td>{{$all->option1}}</td>
           <td>{{$all->option2}}</td>
           <td>{{$all->option3}}</td>
           <td>{{$all->option4}}</td>
           <td>{{$all->answer}}</td>

           <td>
              <div class="form-check">
                <input class="form-check-input big-checkbox" name="present[]" type="checkbox" value="{{$all->id}}" id="defaultCheck1">
             </div>
          </td>

         </tr>  
@endforeach
<button type="submit" class="btn btn-primary save">Submit</button>
</form>

谢谢,Deepti,你能帮我在这个页面添加提交按钮吗code@brij是的,您可以添加HTML提交按钮。这有什么问题吗?当我一个接一个地循环时,什么都不会发生,当我在循环中放置一个按钮时。它显示每一行。当我把按钮放在循环中时,显示错误。“为foreach()提供的参数无效”如果您在以下代码中遇到错误“为foreach()提供的参数无效”
foreach($request->employee_id as$key=>$val)
请尝试像
foreach($request->checked as$key=>$val)那样执行此操作。