Reputation: 23
I am trying to store the data from multiple ratio buttons to the database. And the AJAX post request is below:
$.ajax({
url: '{{ route("checklist.store") }}',
method:'POST',
data:{
_token: CSRF_TOKEN,
data1 : value1,
data2 : value2
},
success:function(data){
console.log('success');
}
});
The message in the console is printed on the console but the item is not created in the database.
Store method in controller :
$hacInspectionsChecklistTable = HacInspectionsChecklistTable::create($request->all());
Upvotes: 2
Views: 357
Reputation: 291
protected $fillable = [
'data1', 'data2'
];
If everything is ok you can try with something like that
$.ajax({
url: '{{ route("route.store") }}',
method:'POST',
data:{
_token: CSRF_TOKEN,
data1 : value1,
data2 : value2
},
success:function(data){
if(data=="created"){
console.log('success');
}
}
});
Route::post('/youroute', [YourController::class, 'store'])->name('route.store');
public function store(Request $request){
$data = new Model();
$data->data1 = $request->data1;
$data->data2 = $request->data2;
$data->save();
return response()->json('created');
}
Upvotes: 1