user6891871
user6891871

Reputation: 174

Update query is not working: 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.

Upvotes: 0

Views: 8544

Answers (3)

Mahdi Younesi
Mahdi Younesi

Reputation: 7489

Update like this

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

Upvotes: 0

Saly
Saly

Reputation: 1496

Try this

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

Upvotes: 1

Abdulla Nilam
Abdulla Nilam

Reputation: 38584

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()

Upvotes: 0

Related Questions