mercredi 27 juillet 2022

Updating an existing record via Laravel eloquent throws exception

I'm struggling to update record in my table using Laravel 5.5. I, basically, have a table that contains a column named status and I'm trying to update the status like this:

public function updateMatchStatus(Request $request) {
        try{
            $match = Match::find($request->id);
            $match->status = $request->status;
            $match->save();
            return response(["message" => "Match status updated"], 200);
        }
        catch(Exception $e){
            return response(["message" => "Error updating match status"], 500);
        }
    }

I have tested and checked the request and it contains the data, it succesfully finds the record to be updated but as soon as I try calling save() it throws exception. I have also tried:

Match::where('id',$request->id)->update(['status' => $request->status]);

Both throw same error:

{
    "message": "SQLSTATE[23514]: Check violation: 7 ERROR:  new row for relation \"matches\" violates check constraint \"matches_status_check\"\nDETAIL:  Failing row contains (7d6dfaa9-c6f6-4548-b9d3-4ddc11137103, E, 2022-07-17 00:00:00, 2022-07-23 00:00:00, 102, 108, PROCESSED, 2022-07-17 18:27:17, 2022-07-27 20:02:47, 5735, 75, 170722-230722, MLB, 16, null). (SQL: update \"matches\" set \"status\" = PROCESSED, \"updated_at\" = 2022-07-27 20:02:47 where \"id\" = 16)",
    "exception": "Illuminate\\Database\\QueryException",
    "file": "/directories/projec/vendor/laravel/framework/src/Illuminate/Database/Connection.php",
    "line": 664,
    "trace": [
        {
         ...
        }
    ]

I am using PostgreSQL. I am unable to understand what possibly is wrong here.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire