I am making simple crud and want to delete favourite list table's columns if user_id and hymn_id matches from favourite_list table
here is my delete route:
Route::resource('fav_hymns', 'Api\favouriteController');
Route::delete('fav_hymns/{user_id}/{hymn_id}/', 'Api\favouriteController@destroy');
and my 'destroy' function in resource favouriteController
public function destroy($user_id,$hymn_id)
{
$favourite_list = favourite_list::where('user_id','=',$user_id, 'AND', 'hymn_id', '=', $hymn_id)->delete();
if (!$favourite_list) {
return response()->json([
'success' => false,
'message' => 'Error: List not found'
], 400);
}
if ($favourite_list) {
return response()->json([
'success' => true
]);
} else {
return response()->json([
'success' => false,
'message' => 'List could not be deleted'
], 500);
}
}
but the problem is, it's deleting all the columns if $user_id matches and $hymn_id (in route) doesn't even exist and doesn't even match, it is deleting all the columns.
Help would be appreciated, thanks