Reputation: 13
I need your help, delete doesn´t work.
public function postUnregisterPushNotifications()
{
try {
$serial_usr = JWTAuth::getPayload(JWTAuth::getToken())->get('sub');
$device_token = Input::get('device_token');
$topic = null;
$device = Device::where('user_id', $serial_usr)->where('token', $device_token);
$device-> delete();
JWTAuth::setToken(JWTAuth::getToken())->invalidate();
return ws_response(false, 'Unregister Notification success', '', 200);
} catch (Exception $ex) {
return ws_response(true, null, 'ERROR ' . $ex->getCode() . '! ' . $ex->getMessage(), 500);
}
}
The insert to the table works but the delete when I logout does not delete from the table
Upvotes: 0
Views: 236
Reputation: 1925
What you're missing here is the ->get()
method which fetches from the database and then ->delete()
method works on the selection.
This should be how your code snippet should look like.
public function postUnregisterPushNotifications()
{
try {
$serial_usr = JWTAuth::getPayload(JWTAuth::getToken())->get('sub');
$device_token = Input::get('device_token');
$topic = null;
$device = Device::where('user_id', $serial_usr)->where('token', $device_token)->get();
$device->delete();
JWTAuth::setToken(JWTAuth::getToken())->invalidate();
return ws_response(false, 'Unregister Notification success', '', 200);
} catch (Exception $ex) {
return ws_response(true, null, 'ERROR ' . $ex->getCode() . '! ' . $ex->getMessage(), 500);
}
}
Upvotes: 1