Reputation: 174
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
Reputation: 7489
Update like this
DB::table('table_name')->where('id', $requst_id)->update(array('status'=>$status));
Upvotes: 0
Reputation: 1496
Try this
DB::table('table_name')->where('id', $requst_id)->update(array('status'=>$status));
Upvotes: 1
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
Might helps Echoing: dd()
vs var_dump()
vs print_r()
Upvotes: 0