How to update row and return id?
11,576
First what your using is not the ORM but the QueryBuilder.
You should assign the query result in a variable, process the update and then access the id.
$client = Client::where("unique_code", $this->unique_code)
->whereHas('types', function ($query) {
$query->where("type", $this->type);
})->first();
$client->update(["status" => 1]);
$client->id; // to get the id
Author by
OPV
Updated on June 14, 2022Comments
-
OPV almost 2 years
I use this function ORM to update row in table:
$client = Client::where("unique_code", $this->unique_code)->whereHas('types', function ($query) { $query->where("type", $this->type); })->update(["status" => 1]);
How to return
id
of updated row? -
Disfigure over 6 yearsthat means no record has been found in your database with your where clause
-
parker_codes over 6 yearsYou can prevent errors by checking if client is set before updating.
-
Alauddin Ahmed over 4 yearsThis is not working if there is multiple records. Do have any way around to get the ids without using another query!