POV
POV

Reputation: 12005

How to update row and return id?

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?

Upvotes: 3

Views: 12824

Answers (1)

Disfigure
Disfigure

Reputation: 740

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

Upvotes: 5

Related Questions