How to fix api json delete requestHow do I test a private function or a class that has private methods, fields or inner classes?How do I format a Microsoft JSON date?Can comments be used in JSON?How can I pretty-print JSON in a shell script?What is the correct JSON content type?How do I test for an empty JavaScript object?Why does Google prepend while(1); to their JSON responses?How can I pretty-print JSON using JavaScript?Parse JSON in JavaScript?How do I POST JSON data with Curl from a terminal/commandline to Test Spring REST?
Unrecognized IC Package Style
Are there any individual aliens that have gained superpowers in the Marvel universe?
How can a warlock learn from a spellbook?
Explain why a line can never intersect a plane in exactly two points.
Setting up the trap
Are intrusions within a foreign embassy considered an act of war?
Definition of 'vrit'
What mathematical theory is required for high frequency trading?
Why is it 出差去 and not 去出差?
「捨ててしまう」why is there two て’s used here?
The Amazing Sliding Crossword
Is using legacy mode instead of UEFI mode a bad thing to do?
Justifying Affordable Bespoke Spaceships
Can the pre-order traversal of two different trees be the same even though they are different?
How is linear momentum conserved in circular motion?
How to write a nice frame challenge?
Syntax and semantics of XDV commands (XeTeX)
Can I apply for a working holiday visa at age 30 and get the full 12 months?
Leaving job close to major deadlines
Implementation of the Jacobi Symbol in C
Why things float in space, though there is always gravity of our star is present
What is the "ls" directory in my home directory?
King or Queen-Which piece is which?
Why are there no file insertion syscalls
How to fix api json delete request
How do I test a private function or a class that has private methods, fields or inner classes?How do I format a Microsoft JSON date?Can comments be used in JSON?How can I pretty-print JSON in a shell script?What is the correct JSON content type?How do I test for an empty JavaScript object?Why does Google prepend while(1); to their JSON responses?How can I pretty-print JSON using JavaScript?Parse JSON in JavaScript?How do I POST JSON data with Curl from a terminal/commandline to Test Spring REST?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
In following code, I'm trying to create a new category (name = 'To be deleted') and then I want to delete it.
first part of the code working fine and I can see new record in the database every time I run the unit test
but I'm having a problem with recode deletion. what's wrong with my code
public function testCategoryDeletion()
$user = AppUser::find(1);
//dd($user->name);
$category = AppCategory::create(['name' => 'To be deleted']);
//dd($category->id);
$response = $this->actingAs($user, 'api')
->json('DELETE', "/api/category/$category->id")
->assertStatus(200)->assertJson([
'status' => true,
'message' => 'Category Deleted',
]);
Test case output
PS C:xampphtdocsChathuraVue_Laravel_API> ./vendor/bin/phpunit
PHPUnit 7.5.7 by Sebastian Bergmann and contributors.
. . . . . . . 7 / 7 (100%)
Time: 1.53 minutes, Memory: 18.00 MB
OK (7 tests, 65 assertions)
PS C:xampphtdocsChathuraVue_Laravel_API>
In database, recode is created but not deleted,
json laravel unit-testing
|
show 2 more comments
In following code, I'm trying to create a new category (name = 'To be deleted') and then I want to delete it.
first part of the code working fine and I can see new record in the database every time I run the unit test
but I'm having a problem with recode deletion. what's wrong with my code
public function testCategoryDeletion()
$user = AppUser::find(1);
//dd($user->name);
$category = AppCategory::create(['name' => 'To be deleted']);
//dd($category->id);
$response = $this->actingAs($user, 'api')
->json('DELETE', "/api/category/$category->id")
->assertStatus(200)->assertJson([
'status' => true,
'message' => 'Category Deleted',
]);
Test case output
PS C:xampphtdocsChathuraVue_Laravel_API> ./vendor/bin/phpunit
PHPUnit 7.5.7 by Sebastian Bergmann and contributors.
. . . . . . . 7 / 7 (100%)
Time: 1.53 minutes, Memory: 18.00 MB
OK (7 tests, 65 assertions)
PS C:xampphtdocsChathuraVue_Laravel_API>
In database, recode is created but not deleted,
json laravel unit-testing
what is error? can you post that also?
– bhavinjr
Mar 25 at 6:18
there is no error, I have updated question please take a look
– Titu
Mar 25 at 6:34
Can you share the related delete method also, may be you returned the array but not deleted it actually?
– Atiqur
Mar 25 at 7:09
Please can you show the controller method and route for the delete route/api/category/category
?
– Ross Wilson
Mar 25 at 7:15
There was an issue with delete method in the controller, I found it and now its working. thank you guys.
– Titu
Mar 25 at 7:23
|
show 2 more comments
In following code, I'm trying to create a new category (name = 'To be deleted') and then I want to delete it.
first part of the code working fine and I can see new record in the database every time I run the unit test
but I'm having a problem with recode deletion. what's wrong with my code
public function testCategoryDeletion()
$user = AppUser::find(1);
//dd($user->name);
$category = AppCategory::create(['name' => 'To be deleted']);
//dd($category->id);
$response = $this->actingAs($user, 'api')
->json('DELETE', "/api/category/$category->id")
->assertStatus(200)->assertJson([
'status' => true,
'message' => 'Category Deleted',
]);
Test case output
PS C:xampphtdocsChathuraVue_Laravel_API> ./vendor/bin/phpunit
PHPUnit 7.5.7 by Sebastian Bergmann and contributors.
. . . . . . . 7 / 7 (100%)
Time: 1.53 minutes, Memory: 18.00 MB
OK (7 tests, 65 assertions)
PS C:xampphtdocsChathuraVue_Laravel_API>
In database, recode is created but not deleted,
json laravel unit-testing
In following code, I'm trying to create a new category (name = 'To be deleted') and then I want to delete it.
first part of the code working fine and I can see new record in the database every time I run the unit test
but I'm having a problem with recode deletion. what's wrong with my code
public function testCategoryDeletion()
$user = AppUser::find(1);
//dd($user->name);
$category = AppCategory::create(['name' => 'To be deleted']);
//dd($category->id);
$response = $this->actingAs($user, 'api')
->json('DELETE', "/api/category/$category->id")
->assertStatus(200)->assertJson([
'status' => true,
'message' => 'Category Deleted',
]);
Test case output
PS C:xampphtdocsChathuraVue_Laravel_API> ./vendor/bin/phpunit
PHPUnit 7.5.7 by Sebastian Bergmann and contributors.
. . . . . . . 7 / 7 (100%)
Time: 1.53 minutes, Memory: 18.00 MB
OK (7 tests, 65 assertions)
PS C:xampphtdocsChathuraVue_Laravel_API>
In database, recode is created but not deleted,
json laravel unit-testing
json laravel unit-testing
edited Mar 25 at 7:14
Ross Wilson
18.8k33043
18.8k33043
asked Mar 25 at 6:07
TituTitu
418
418
what is error? can you post that also?
– bhavinjr
Mar 25 at 6:18
there is no error, I have updated question please take a look
– Titu
Mar 25 at 6:34
Can you share the related delete method also, may be you returned the array but not deleted it actually?
– Atiqur
Mar 25 at 7:09
Please can you show the controller method and route for the delete route/api/category/category
?
– Ross Wilson
Mar 25 at 7:15
There was an issue with delete method in the controller, I found it and now its working. thank you guys.
– Titu
Mar 25 at 7:23
|
show 2 more comments
what is error? can you post that also?
– bhavinjr
Mar 25 at 6:18
there is no error, I have updated question please take a look
– Titu
Mar 25 at 6:34
Can you share the related delete method also, may be you returned the array but not deleted it actually?
– Atiqur
Mar 25 at 7:09
Please can you show the controller method and route for the delete route/api/category/category
?
– Ross Wilson
Mar 25 at 7:15
There was an issue with delete method in the controller, I found it and now its working. thank you guys.
– Titu
Mar 25 at 7:23
what is error? can you post that also?
– bhavinjr
Mar 25 at 6:18
what is error? can you post that also?
– bhavinjr
Mar 25 at 6:18
there is no error, I have updated question please take a look
– Titu
Mar 25 at 6:34
there is no error, I have updated question please take a look
– Titu
Mar 25 at 6:34
Can you share the related delete method also, may be you returned the array but not deleted it actually?
– Atiqur
Mar 25 at 7:09
Can you share the related delete method also, may be you returned the array but not deleted it actually?
– Atiqur
Mar 25 at 7:09
Please can you show the controller method and route for the delete route
/api/category/category
?– Ross Wilson
Mar 25 at 7:15
Please can you show the controller method and route for the delete route
/api/category/category
?– Ross Wilson
Mar 25 at 7:15
There was an issue with delete method in the controller, I found it and now its working. thank you guys.
– Titu
Mar 25 at 7:23
There was an issue with delete method in the controller, I found it and now its working. thank you guys.
– Titu
Mar 25 at 7:23
|
show 2 more comments
1 Answer
1
active
oldest
votes
I fixed the controller as follows and now its working,
public function destroy(Category $category)
$status = $category->delete();
return response()->json([
'status' => $status,
'message' => $status ? 'Category Deleted' : 'Error Deleting Category'
]);
API routes
Route::group(['middleware' => 'auth:api'], function()
Route::resource('/task', 'TaskController');
Route::resource('/category', 'CategoryController');
Route::get('/category/category/tasks', 'CategoryController@tasks');
);
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55332065%2fhow-to-fix-api-json-delete-request%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
I fixed the controller as follows and now its working,
public function destroy(Category $category)
$status = $category->delete();
return response()->json([
'status' => $status,
'message' => $status ? 'Category Deleted' : 'Error Deleting Category'
]);
API routes
Route::group(['middleware' => 'auth:api'], function()
Route::resource('/task', 'TaskController');
Route::resource('/category', 'CategoryController');
Route::get('/category/category/tasks', 'CategoryController@tasks');
);
add a comment |
I fixed the controller as follows and now its working,
public function destroy(Category $category)
$status = $category->delete();
return response()->json([
'status' => $status,
'message' => $status ? 'Category Deleted' : 'Error Deleting Category'
]);
API routes
Route::group(['middleware' => 'auth:api'], function()
Route::resource('/task', 'TaskController');
Route::resource('/category', 'CategoryController');
Route::get('/category/category/tasks', 'CategoryController@tasks');
);
add a comment |
I fixed the controller as follows and now its working,
public function destroy(Category $category)
$status = $category->delete();
return response()->json([
'status' => $status,
'message' => $status ? 'Category Deleted' : 'Error Deleting Category'
]);
API routes
Route::group(['middleware' => 'auth:api'], function()
Route::resource('/task', 'TaskController');
Route::resource('/category', 'CategoryController');
Route::get('/category/category/tasks', 'CategoryController@tasks');
);
I fixed the controller as follows and now its working,
public function destroy(Category $category)
$status = $category->delete();
return response()->json([
'status' => $status,
'message' => $status ? 'Category Deleted' : 'Error Deleting Category'
]);
API routes
Route::group(['middleware' => 'auth:api'], function()
Route::resource('/task', 'TaskController');
Route::resource('/category', 'CategoryController');
Route::get('/category/category/tasks', 'CategoryController@tasks');
);
answered Mar 25 at 7:26
TituTitu
418
418
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55332065%2fhow-to-fix-api-json-delete-request%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
what is error? can you post that also?
– bhavinjr
Mar 25 at 6:18
there is no error, I have updated question please take a look
– Titu
Mar 25 at 6:34
Can you share the related delete method also, may be you returned the array but not deleted it actually?
– Atiqur
Mar 25 at 7:09
Please can you show the controller method and route for the delete route
/api/category/category
?– Ross Wilson
Mar 25 at 7:15
There was an issue with delete method in the controller, I found it and now its working. thank you guys.
– Titu
Mar 25 at 7:23