Ok, those are going to be 2 separate ajax calls (one for delete, one for adding), going to 2 separate controller methods (delete/store).
So in each of those 2 controller methods, you'd just return what you need and take appropriate action in the success method.
To create, it's basically just like the tutorial, except instead of just returning a status message, you'd also (or instead) return the grocery that was just created.
public function store(Request $request)
{
$grocery = new Grocery();
$grocery->name = $request->name;
$grocery->type = $request->type;
$grocery->price = $request->price;
$grocery->save();
return response()->json([
'success'=>'Data is successfully added',
'grocery' => $grocery->toArray()
]);
}
And then in the success event, it would be like
success: function(result) {
// unhide the element with the class of .alert (which has display:none)
jQuery('.alert').show();
// populate .alert element with the 'success' property returned from the ajax call
jQuery('.alert').html(result.success);
// create a div to hold the grocery data
var div = '<div>Name: ' + result.grocery.name + ', Type: ' + result.grocery.type + '</div>';
// insert it somewhere in the dom
jQuery('#some-div').html(div);
}});
And in the html of the page, you'd have <div id="some-div"></div> or something, which would get populated with the contents of the div just created
The delete would be similar, except you'd just pass back the id of the thing that was deleted, and remove it from the dom.
assume you have this on the page
<div id="grocery-3">some data for grocery with id of 3</div>
<div id="grocery-4">some data for grocery with id of 4</div>
and in the success event:
success: function(result) {
// let's say id 4 was sent to be deleted, and being returned as 'id'
// find that #grocery and remove it from the dom
jQuery('#grocery-' + result.id).remove();
}
Of course, there is a lot to this and I didn't explain 100% of everything, but that's the gist of it. It's a lot to go over...