Laravel 语法::parameterize():参数#1($values)的类型必须为array、string给定、called

Laravel 语法::parameterize():参数#1($values)的类型必须为array、string给定、called,laravel,laravel-5,eloquent,laravel-4,laravel-8,Laravel,Laravel 5,Eloquent,Laravel 4,Laravel 8,这是我的控制器,名为“AttendanceController” 这是我的出席。在有表格提交的地方创建 <form method="post" action="{{route('attendances.store')}}"> @csrf <table> <tr> <th><p style="

这是我的控制器,名为“AttendanceController”

这是我的出席。在有表格提交的地方创建

<form method="post" action="{{route('attendances.store')}}">
        @csrf
        <table>

                <tr>
                    <th><p style="margin: 20px">Name : </p></th>
                    <th><p style="margin: 20px">Attendance : </p></th>
                    <th><p style="margin: 20px">Date : </p></th>
                </tr>
            @foreach ($students as $student)
                <tr>
                    <th><p style="margin: 20px">{{ $student->name }}</p></th>
                    <input name="id[]" type="hidden" value="{{ $student->id }}">
                    <th><p style="margin: 20px">
                        <select name="attendance[]" id="attendance">
                            <option value="present">present</option>
                            <option value="absent">absent</option>
                            <option value="half_day">half day</option>
                        </select></p>
                    </th>
                    <th><p style="margin: 20px"><input type="date" class="form-control" name="date[]"></p></th>
                </tr>

            @endforeach
            <td><button class="btn btn-primary" name="submit" id="submit">Submit</button></td>
        </table>
    </form>

@csrf
名称:

出席人数:

日期:

@foreach($student作为$student)

{{$student->name}

目前 缺席的 半天

@endforeach 提交
您的输入名称会导致冲突。您发送了多个学生的表单字段,但未确认这些字段

我并没有检查代码,但我希望你们会明白

<form method="post" action="{{route('attendances.store')}}">
        @csrf
        <table>

                <tr>
                    <th><p style="margin: 20px">Name : </p></th>
                    <th><p style="margin: 20px">Attendance : </p></th>
                    <th><p style="margin: 20px">Date : </p></th>
                </tr>
            @foreach ($students as $key => $student)
                <tr>
                    <th><p style="margin: 20px">{{ $student->name }}</p></th>
                    <input name="student[{{$key}}][id]" type="hidden" value="{{ $student->id }}">
                    <th><p style="margin: 20px">
                        <select name="student[{{$key}}][attendance]" id="attendance">
                            <option value="present">present</option>
                            <option value="absent">absent</option>
                            <option value="half_day">half day</option>
                        </select></p>
                    </th>
                    <th><p style="margin: 20px"><input type="date" name="student[{{$key}}][date]" class="form-control"></p></th>
                </tr>

            @endforeach
            <td><button class="btn btn-primary" name="submit" id="submit">Submit</button></td>
        </table>
    </form>

哪一行抛出这个错误?无论如何,我在
store
function
$students=Student::all()上发现了一行不必要的内容
<form method="post" action="{{route('attendances.store')}}">
        @csrf
        <table>

                <tr>
                    <th><p style="margin: 20px">Name : </p></th>
                    <th><p style="margin: 20px">Attendance : </p></th>
                    <th><p style="margin: 20px">Date : </p></th>
                </tr>
            @foreach ($students as $key => $student)
                <tr>
                    <th><p style="margin: 20px">{{ $student->name }}</p></th>
                    <input name="student[{{$key}}][id]" type="hidden" value="{{ $student->id }}">
                    <th><p style="margin: 20px">
                        <select name="student[{{$key}}][attendance]" id="attendance">
                            <option value="present">present</option>
                            <option value="absent">absent</option>
                            <option value="half_day">half day</option>
                        </select></p>
                    </th>
                    <th><p style="margin: 20px"><input type="date" name="student[{{$key}}][date]" class="form-control"></p></th>
                </tr>

            @endforeach
            <td><button class="btn btn-primary" name="submit" id="submit">Submit</button></td>
        </table>
    </form>
public function store(Request $request)
{
    $request->validate(array(
        'student' => 'array|required', // laravel array validaton.
        'student.*.id' => 'required', // array item validator with asterisk: https://laravel.com/docs/8.x/validation#validating-arrays
        'student.*.attendance' => 'required',
        'student.*.date' => 'required',
    ));

   foreach($request->get('student') as $student)

      $attendance = Attendance::create(array(
          'student_id' => $student['id'], // if you use in there.
          'attendance' => $student['attendance'],
          'date' => $student['date'],
      ));

   }

    return redirect()->route('attendances.index')->withSuccess('Done');
}