在Laravel 5.7中更新行不起作用,我该如何解决?

I'm trying to update a row in mysql table. However, when I click the register button, it doesn't do anything. I'm using Laravel.

Here's my update function:

public function update(Request $request)
{
    $idpawn = $request['idprestamo'];
    $paynumber = $request['numeropago'];
    $payqty = $request['payqty'];
    $statuspawns = statuspawns::find($idpawn,$paynumber);
    $updateqty = $statuspawns->totalpayment - $payqty;

    if($updateqty  == "0"){
        $status = "Pay";
    }
    else{
        $status = "Partial Payment";
    }

    $statuspawns->total = $updateqty;
    $statuspawns->status = $status;
    $statuspawns->save();

    return redirect()->back();
}

Thanks for your help.

I think the problem might be that you need square brackets instead of parenthesis since it's an array. $request['idprestamo'] $request['numeropago'] $request['payqty']

I'd like to also add that you can do it this way also with a magic method...

$request->numeropago

You have to access the Request this way $request->input_name not this way $request('input_name') because it is a Laravel Data Collection

In the end of the day, your function will look like this:

public function update(Request $request)
    {
        $idpawn = $request->idprestamo;
        $paynumber = $request->numeropago;
        $payqty = $request->payqty;
        $statuspawns = statuspawns::find($idpawn,$paynumber);
        $updateqty = $statuspawns->totalpayment - $payqty;

        if($updateqty  == "0"){
            $status = "Pay";
        }
        else{
            $status = "Partial Payment";
        }

        $statuspawns->total = $updateqty;
        $statuspawns->status = $status;
        $statuspawns->save();

        return redirect()->back();
    }

UPDATE

In Laravel 5.7 you have to use the update() method instead of the save() method to update a row.

You are not retrieving the record correctly. you have to pass only id to find(). As you have passed two parameters.

change this statement to..

$statuspawns = statuspawns::find($idpawn,$paynumber);

To

$statuspawns = statuspawns::find($idpawn);

Now you can update the columns which you want to update.