I am using postman
to send post request as json file to the tasks table. this is My api.php route
Route::post('/tasks', 'TaskController@create');
and TaskController
public function create(Request $request)
{
$rules = [
'name' => 'required',
'owner' => 'required'
];
$validate = Validator::make($request->all(), $rules);
if ($validate->fails()) {
return $validate->errors();
}
return Task::create([
'name' => $request->title,
'owner' => $request->status
]);
}
and I have following url in postman http://localhost:8000/api/tasks
with POST request and under the ‘Body’ tab choose the ‘raw’ radio button and then ‘JSON (application/json)’ from the drop down. and send data body in postman is like this.
{
"name": "sara",
"owner": "mala"
}
but when send data it is not saving to the table and occured following error massage. SQLSTATE[23000]: Integrity constraint violation: 1048 Colum 'name' cannot be null
how can fix this problem?
from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2OAiDcV
via IFTTT
Aucun commentaire:
Enregistrer un commentaire