Laravel Cannot Save data to DB after Pessimistic Locking
I am facing the problem that cannot update data to db while using save method with Laravel 5.1.
I am trying to update data with locking to avoid concurrency data and below is my code.
Please help me.
namespace App\Model;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
class Recharge extends Model
{
public function processSuccess($orderId, $type, $amount) {
        $query = [
            ['status', '<=', 1],
            ['order_abm', '=', $orderId],
            ['type', '=', $type],
            ['amount', '=', $amount],
        ];
        \DB::beginTransaction();
        $concur_up = Recharge::where($query)->lockForUpdate()->get();
        $concur_up->status = 5;
        $concur_up->amounted = $amount;
        $concur_up->date    = time();
        $res =$concur_up->save();
        if (!$res) {
            return "fail";
        }
        \DB::commit();
        return true;
    }
}
error shown in my editor
error shown in my browser
My using table
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire