Store data into database using request json string in laravel

I am having a table name Student ( id , name , division ). To store data into this table I am sending json string as a request to the api in laravel.

Request json string is,

{
"name":"abc",
"division":"a",
"city":"xyz"
}

Controller Code

 public function registerStudent(Request $request){

$requestData = $request->json()->all();
$studentModel = Student::create($requestData);

}

Student Model

class Student extends Model
{
protected $fillable = [
'id', 'name','division'
];


}

When i execute this code , i get the following error,

Illuminate\Database\QueryException: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'city' in 'field list' (SQL: insert into `Student`... 

now my question here is, in what way I can store the data into database from json request with having extra keys into json object/array.



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2UxnGOT
via IFTTT

تعليقات