rinvex/laravel-addresses

Delete function not working properly in accordance with eloquent delete function?

Closed this issue · 4 comments

Hi there,

I am deleting the model but it is throwing an exception.

Illuminate/Database/Eloquent/ModelNotFoundException with message 'No query results for model [Rinvex/Addresses/Models/Address].'

The above exception makes the next code invalid and instantly get the 404 not found. After deletion, it should return the "true" boolean value.

My controller code is as below:

 public function destroy(Address $location)
    {
        $business = $location->addressable;

        $location->delete();

        notify()->success(__('Your location and address is successfully deleted.'));

        return redirect()->route('businesses.locations.index', $business);

    }

Could you please assist me to resolve the issue?

blwsh commented

@MHassanSaqib I managed to get this test to pass. It deletes all addresses belonging to a model. You can refine which addresses should be deleted using where.

    public function testDeleteAddressDisassociates()
    {
        $this->testAttachAddressToJob(); // Add a job
        $this->assertEquals(1, $this->job->addresses()->delete());
        $this->assertCount(0, $this->job->refresh()->addresses);
    }

@MHassanSaqib I managed to get this test to pass. It deletes all addresses belonging to a model. You can refine which addresses should be deleted using where.

    public function testDeleteAddressDisassociates()
    {
        $this->testAttachAddressToJob(); // Add a job
        $this->assertEquals(1, $this->job->addresses()->delete());
        $this->assertCount(0, $this->job->refresh()->addresses);
    }

It is deleting the addresses but as soon as $location->delete(); line from my snippet runs. It breaks the next code because it is redirecting back with 404 status.. I copied the code and remove events (I think), that fixed this problem..

Having same problem "No query result found" error on deletion. any update??

There was some issues with the fired eloquent delete event, and it's been fixed. I'm assuming that was the reason for this issue, so please check latest release and let me know if it still exists or if you've any further issues.