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;








0















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,



database










share|improve this question
























  • 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

















0















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,



database










share|improve this question
























  • 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













0












0








0








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,



database










share|improve this question
















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,



database







json laravel unit-testing






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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

















  • 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












1 Answer
1






active

oldest

votes


















0














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');
);





share|improve this answer























    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
    );



    );













    draft saved

    draft discarded


















    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









    0














    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');
    );





    share|improve this answer



























      0














      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');
      );





      share|improve this answer

























        0












        0








        0







        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');
        );





        share|improve this answer













        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');
        );






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 25 at 7:26









        TituTitu

        418




        418





























            draft saved

            draft discarded
















































            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.




            draft saved


            draft discarded














            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





















































            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







            Popular posts from this blog

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

            Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript