I have this controller method:
<?php
public function ignore($id)
{
Log::info($id);
$st = Servicetype::destroy($id);
Log::info($st);
// $st->delete();
return response(null, Response::HTTP_OK);
}
Also, this route in Api.php:
Route::delete('/servicetypelinking/{id}/ignore', 'PlanningCenter\Controllers\ServiceTypeLinkingController@ignore');
I'm calling the route from a Vue.js method that looks like this:
ignore(id) {
console.log('In the ignore method: ' + id);
this.mute = true;
window.axios.delete('/api/servicetypelinking/' + id + '/ignore').then(({ response }) => {
console.log(response);
let index = this.serviceTypes.findIndex(serviceType => serviceType.id === id);
this.serviceTypes.splice(index, 1);
this.mute = false;
});
}
The Vue side is working, and the service type is "deleted" on the screen. Nothing is happening in the database.
When I run this for id=16 I get this in the laravel.log which shows that the right method and the right id are correct:
[2018-11-26 17:27:42] local.INFO: 16 <-- This is passed in
[2018-11-26 17:27:42] local.INFO: 0 <-- Result of the destroy operation
I can also do a Servicetype::find(16)->toArray() on this model and it retrieves the data and displays it in the log.
If I create a web route to this controller method and do a get with the id, the delete happens in the database. For some reason, even though the id is getting to the method, calling the destroy method on the model isn't doing anything.
Is there some secret Laravel thing going on here? Any help is appreciated.
Additional Info: There doesn't appear to be anyhting wrong on the Vue/javascript side. No errors in the console, the request is sent properly (using my original as well as the suggested with the _delete parameter.) I have verified that it is getting to the method. I have also hardcoded the id into the destroy() method and it is still not deleting the record. No errors in the laravel error log, either. Everything should work but it isn't.
Solution: I din't really find a solution to the problem so I worked around it. Using
Servicetype::destroy($id);
did nothing. But, using:
DB::table('servicetypes')->where('id', $id)->delete();
did work. I was hoping to use softdeletes but found some other issues with that and using query builder so in the end I did a little re-coding to make the problem "go away." I may dig into it some more when I have time. It was strange behavior.
Solution: I din't really find a solution to the problem so I worked around it. Using
Servicetype::destroy($id);
did nothing. But, using:
DB::table('servicetypes')->where('id', $id)->delete();
did work. I was hoping to use softdeletes but found some other issues with that and using query builder so in the end I did a little re-coding to make the problem "go away." I may dig into it some more when I have time. It was strange behavior. I updated the description accordingly.