prgrm
prgrm

Reputation: 3833

Laravel returns error after deleting a record

I have a function like this:

protected function delete_failed_payment($token)
{
    $invoice = Invoice::where("owner_id",Auth::user()->owner_id)
        ->where("token",$token)
        ->where("completed","0")
        ->first();

    Invoice::destroy($invoice->id);

    return redirect("/")->withErrors("Fail!");
}

After calling this function, the record gets succesfully deleted, but I get this error response in return:

UnexpectedValueException

The Response content must be a string or object implementing __toString(), "boolean" given.

…/vendor/symfony/http-foundation/Response.php line 407

I am expecting it to redirect me to "/" but even though the record gets deleted and there seems to be no problem, it won't let me.

I have also tried this:

$invoice = Invoice::where("owner_id",Auth::user()->owner_id)
        ->where("token",$token)
        ->where("completed","0")
        ->delete();

With the same result as before.

Any help?

Upvotes: 0

Views: 659

Answers (2)

kerrin
kerrin

Reputation: 3452

Try

protected function delete_failed_payment($token)
{
    $invoice = Invoice::where("owner_id",Auth::user()->owner_id)
            ->where("token",$token)
            ->where("completed","0")
            ->first();

    Invoice::destroy($invoice->id);

    return redirect('/')
        ->withErrors(array('message' => 'Fail!'));
}

Upvotes: 1

Jerico Pulvera
Jerico Pulvera

Reputation: 1042

Try this.

protected function delete_failed_payment($token)
{
    $invoice = Invoice::where("owner_id",Auth::user()->owner_id)
        ->where("token",$token)
        ->where("completed","0")
        ->first();

    $invoice->delete();

    return redirect->to("/")->withErrors("message" => "Fail!");
}

Upvotes: 1

Related Questions