Juvenile
Juvenile

Reputation: 11

Laravel update query use

I used this query to update the status column.

$val="1";
vehicles::where('id' , '=' , $veh_status)->update(['status' => $val]);

But when I submitted the status value doesn't change.

Upvotes: 1

Views: 1091

Answers (2)

Edgar
Edgar

Reputation: 552

Not sure what the problem is there because you haven't given much info to work with, but you can check these suggestions:

  • Check if the column is set to be mass assignable in the model class, that is, it is in the fillable[] array.
  • make sure the id you pass to the where() function is valid.
  • Try using another function, save() which will achieve the same results you seek, like this;

    // filter the vehicle $vehicle = vehicles::where('id', '=', $veh_id)->first(); or $vehicle = vehicles::find($veh_id); $vehicle->status = 1; $vehicle->save();

Lastly, I noticed your id variable you pass to the where the () function is called $veh_status "presumably - vehicle status" and not $veh_id, "presumably - vehicle id" so probably check that out.

Ref: Laravel Model Update documentation

Upvotes: 1

Mehdi Meshkatian
Mehdi Meshkatian

Reputation: 308

you can trace your query by using ->toSql() method ! try this to find whats happening in back

Upvotes: 1

Related Questions