更新查询无效:Laravel

I'm used to write the update query but for now it's not working for me in laravel. I have write the update query like this.

DB::table('table_name')->where(['id'=>$requst_id])->update(array('status'=>$status)

When i run dd().it's getting 0 to me

But with same condition i used

DB::table('table_name')->where(['id'=>$requst_id])->first();

I got the data. Can anyone suggest me where i'm going wrong. Thanks in advance.Any help will be appreciated.

Try this

DB::table('table_name')->where('id', $requst_id)->update(array('status'=>$status));

it's because UPDATE return count and SELECT returns data/array.

This is SELECT

DB::table('table_name')->where(['id'=>$requst_id])->first();

This is UPDATE

DB::table('table_name')->where(['id'=>$requst_id])->update(array('status'=>$status));

Do like this

$affectedRows = DB::table('table_name')->where(['id'=>$requst_id])->update(array('status'=>$status));
echo "Affected rows are/is: " . $affectedRows;

If Prints

  1. 0 - No Changes
  2. 1 - One row was changed
  3. 1> - N number of rows updated.

Might helps Echoing: dd() vs var_dump() vs print_r()

Update like this

DB::table('table_name')->where('id', $requst_id)->update(array('status'=>$status));