In an application in Laravel I have several scripts using ajax. All expect a response from the controller script and, if true, I run a certain function with ajax ' success '
Example of how I'm doing:
script.js
$.ajax({
type: 'GET',
dataType: 'json',
url: '/teste',
data: {value:value},
success: function(data){
//Alguma função
}
});
TestController.php
public function teste(Request $request){
$value = $request->value;
/* Alguma função com o value*/
return response()->json(['success' => true]);
}
But I need it to return false in case of an error. But I have no idea and how to test this, I wanted to add an error test for all the scripts (and I do not even know if it is correct or necessary) in several cases ( database query ), working with < strong> session and etc). I know the try / catch but I've never used it and I can hardly see anyone using some code, so I'm kind of lost with it.