Lois Arce
Lois Arce

Reputation: 69

Laravel: Query Exception

Array to string conversion (SQL: insert into RegisterStudent (LRN, dateOfBirth, sex, updated_at, created_at) values (1234, 1996-02-10, Female, 2017-10-26 05:30:32, 2017-10-26 05:30:32))

enter image description here

StudentController store content

public function store(Request $request){

     //validation
    $this->validate($request, [
        'LRN' => 'required|max:100',
    ]);

    $student = New Student;
    $student->LRN = $request->input('LRN');
    $student->dateOfBirth = $request->input('dateOfBirth');
    $student->sex = $request->input('sex');

    $student->save();

    return redirect()->back();
}

Upvotes: 0

Views: 93

Answers (1)

madalinivascu
madalinivascu

Reputation: 32354

Change the following:

$student->sex = $request->input('sex')[0];

the input seems to be a array so you need the value at [0] or remove the [] in your input name to use in php $request->input('sex')

Upvotes: 1

Related Questions