laravel 4 如何将复选框的值作为数组从视图传递到控制器

how to pass the value of checkboxes as an array from view to controller in laravel 4

我想知道如何将多个复选框的值作为数组从我的视图传递到控制器。 这是我的代码:

我的看法:

@extends('layouts.master')

@section('content')

<?php
    $count = 1;
?>

{{ Form::open(array('method' => 'POST', 'action' => array('createQuizController@addQuestion'), 'id' => 'add_question')) }}

<div class="col-lg-10 col-lg-offset-1">
    <div class="table-responsive" id="question_table">
        <table class="table table-bordered table-striped">
            <thead>
            <tr>
                <th>ردیف</th>
                <th>عنوان سوال</th>
                <th></th>
            </tr>
            </thead>

            <tbody>
            @foreach ($result as $quiz)
                <tr>
                    <td align="center" width="100px">
                        <?php echo $count++; ?>
                    </td>
                    <td align="center" width="200px">{{ $quiz->title }}</td>
                    <td align="center" width="200px"><input type="checkbox" name="select_question[]" id="counter[]" value="{{ $quiz->lesson_id }}"></td>
                </tr>
            @endforeach
            </tbody>
        </table>
    </div>
</div>
{{ Form::submit('افزودن', ['class' => 'btn btn-primary']) }}

{{ Form::close() }}

<input type="text" id="count-checked" name="count-checked">

@stop

我想post复选框的值; $quiz->lesson_id 作为我的控制器方法的数组 addQuestion.

你快到了。我相信以下构造将为您生成数组,其中每个复选框都设置了正确的 ID。

<input type="checkbox" name="select_question[{{ $quiz->lesson_id }}]" id="counter_{{ $quiz->lesson_id }}">