I have the following function in jquery that gives the delete in the registry. It even deletes the record but does not go to success
, it goes to error
. Why?
function deletar_cliente(id_cliente)
{
var mensagem_sucesso = "";
var mensagem_erro = "";
var url_cliente = "cadastro_clientes.php";
$.ajax({
url: url_base + "clientes/" + id_cliente,
type: 'DELETE',
dataType: 'json',
}).success(function(data)
{
console.log(data);
}).error(function(data)
{
console.log('erro');
});
}
CLIENTS CONTROLLER:
public function destroy($id)
{
$clientes = Clientes::find($id);
if(!$clientes) {
return response()->json([
'message' => 'Cliente não encontrado',
], 404);
}
$clientes->delete();
}
ROUTES:
use Illuminate\Http\Request;
Route::get('/', function () {
return response()->json(['message' => 'Rep Api', 'status' => 'Connected']);;
});
Route::resource('clientes', 'ClientesController');
Route::resource('fornecedores', 'FornecedoresController');
Route::resource('usuarios', 'UsuariosController');
Route::resource('estados', 'EstadosController');
Route::resource('municipios', 'MunicipiosController');
Route::post('autenticacao', 'AuthController@authenticate');
Route::get('get-municipios/{estados_id}', 'MunicipiosController@getMunicipios');