<?php
// when form is posted here via AJAX
function action_in_controller(Request $request){
try {
$validator = Validator::make($request->all(), [
'name' => 'required',
'description' => 'required',
'price' => 'required',
'price_btc' => 'required',
'file_resource' => 'required'
]);
if ($validator->fails()) {
// return all validation errors as array
return response()->json(['status' => 'error', 'error' => $validator->errors(), 'point' => 'validation failed']);
}
} catch (\Exception $e) {
// unknown exception, pass message as array
return response()->json(['status' => 'error', 'error' => [$e->getMessage()], 'point' => 'exception']);
}
}
?>