Laravel上的错误状态500 Ajax

Good I am trying to delete through ajax but I get the following error:

Failed to load resource: the server responded with a status of 500 (Internal Server Error)

I searched the error and apparently appears by the token so I have done what they recommended, I added in the view this:

<meta name="csrf-token" content="{{ csrf_token() }}">

ajax:

$('#delete').on('click', function(){
    var x = $(this);
    var delete_url = x.attr('data-href')+'/'+x.attr('data-id');

    $.ajax({
        url: delete_url,
        type:'DELETE',
        headers:{
            "X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr('content')
        },
        success:function(result){
            alert('success');
        },
        error:function(result){
            alert('error');
        }
    });
});

controller:

public function destroy($id)
{
    $appointment = Appointment::find($id);

    if(appointment == null) {
        return Response()->json([
            'message'=>'error delete.'
        ]);
    }

    $appointment->delete();

    return Response()->json([
        'message'=>'sucess delete.'
    ]);
}

route:

Route::name('appointments.destroy')->delete('/citas/{id}', 'AppointmentController@destroy');

it is certainly a token error because if I do not need it on the route it does it perfectly ...

class VerifyCsrfToken extends BaseVerifier
{
    /**
     * The URIs that should be excluded from CSRF verification.
     *
     * @var array
     */
    protected $except = [
        'citas/*'
    ];
}

You can check the exact error on developers console, network tab. Look there for your request and check the preview or open it in a new chrome's tab.

Posted code has a typo, maybe it is in your file too? You missed to add $ to your appointment variable.

public function destroy($id)
{
    $appointment = Appointment::find($id);

    if($appointment == null) {
        return Response()->json([
            'message'=>'error delete.'
        ]);
    }

    $appointment->delete();

    return Response()->json([
        'message'=>'sucess delete.'
    ]);
}