0👍
Simple use
$request->student;
student/year/age is a part of your $request
body and laravel can access it like that.
Just an important note that $request
is coming from the
Illuminate\Http\Request;
So make sure to use
it in your file and inject it in your function like:
public function createRecord(Request $request){
return Students::create([
'student'=> $request->student,
'year'=> $request->year,
'age'=> $request->age,
]);
}
0👍
You said you’re able to return $request->addStudent
and you get the desired response: {student: "test", year: 1, age: "13"}
. This means you need to access the request properties like this:
return Students::create([
'student': $request->addStudent['student'],
'year': $request->addStudent['year'],
'age': $request->addStudent['age'],
]);
Alternatively, you could configure your axios request to send the addStudent
object as the request body like this:
axios.post('./api/po', this.addStudentForm);
Then you’ll be able to access the properties individually right off the request:
return Students::create([
'student': $request->student,
'year': $request->year,
'age': $request->age,
]);
- [Vuejs]-SyntaxError: Unexpected token … in serialport in node_modules
- [Vuejs]-Display RSS Feed or API on Vue application
Source:stackexchange.com