samedi 3 avril 2021

Grammar::parameterize(): Argument #1 ($values) must be of type array, string given, called

This is my Controller named "AttendanceController". This is my Controller named "AttendanceController"

public function index()
{
    $attendances = Attendance::orderBy('date', 'desc')->paginate(50);
    $students = Student::all();
    return view('attendances.index', compact('attendances', 'students'));
}
public function create()
{
    $students = Student::all();
    return view('attendances.create', compact('students'));
}
public function store(Request $request)
{
    $students = Student::all();
    $request->validate(array(
        'attendance' => 'required',
        'date' => 'required',
    ));

    $attendance = Attendance::create(array(
        'attendance' => $request->input('attendance'),
        'date' => $request->input('date'),
    ));

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

This is my attendances.create where There is form to submit. This is my attendances.create where There is form to submit.

<form method="post" action="">
        @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"></p></th>
                    <input name="id[]" type="hidden" value="">
                    <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>


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire